0

In firefox, i made a greasemonkey script that is working pretty well everywhere but twitter's page. Does twitter have some kind of protection against javascript plugins? If so, are there any workaround?

// ==UserScript==
// @name        teste.js
// @namespace   teste.js
// @version     1
// @grant       none
// @include     *://www.twitter.com*
// @include     *://www.google.com*
// @include     *://www.facebook.com*
// @run-at      document-start
// ==/UserScript==

var pressedKey = 1;
var scroll;

function KeyCheck(e)
{
   var x = e.which || e.keyCode;
  console.log(e);
 if (x == 97)
    {
     clearInterval(scroll);

        if ( pressedKey == 1 )
        {
        scroll = setInterval(function(){ window.scrollBy(0,1); }, 50);
        pressedKey = -pressedKey;

        //document.getElementById("demo").style.backgroundColor = "red";
        }
        else if (pressedKey == -1)
        {
        pressedKey = -pressedKey;

        //document.getElementById("demo").style.backgroundColor = "blue";
        }
    }
}
window.addEventListener('keydown', KeyCheck, true);
Matheus
  • 21
  • 2
  • 1
    We can't help you if you don't give us any details. What does this script do? What do you mean by "it doesn't work"? Does it raise errors? Can you tell what it attempts to do before it fails? Does greasemonkey even run it on the page? – Shadow Oct 26 '17 at 02:18
  • Edited and put the code right up. So, the greasymonkey seems to not recognize the script while at twitter's page. The script works if i put it directly in the console. – Matheus Oct 26 '17 at 02:30

2 Answers2

1

As suggested, it is best to provide more information about the steps taken to troubleshoot and specifics about the script you are attempting to execute.

HOWEVER, I believe what is happening here is Twitter employs a "Content Security Policy directive" on their server that will refuse injection of scripts.

You can witness the failure by opening the Developer Tools in your browser and looking at the JavaScript Console output.

This answer related to CSP may be helpful to you, but I expect there is not much that can be done since this is being controlled on their servers.

CreMedian
  • 763
  • 5
  • 15
1

found the problem. I Changed

// @include     *://www.twitter.com*

to

// @include    *twitter.com* 

and it is working now. :D

Matheus
  • 21
  • 2