Page 1 of 1

NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 10:52 am
by Greg01010100
Hi guys. First of all thanks for this extension making Internet much safer. :) I have little userscript (Greasemonkey) that adds context menu item. Problem is it works only when i allow site. Is there any way to make it work without allowing site, cause this makes noscript pointless?

Code:

Code: Select all

// ==UserScript==
// @name            Instapaper context menu
// @grant           GM_openInTab
// ==/UserScript==
var menu = document.body.appendChild(document.createElement('menu'));
menu.id = 'instapaper-context-menu';
menu.type = 'context';
menu.innerHTML = '<menuitem label="Read on Instapaper" icon="https://staticinstapaper.s3.amazonaws.com/images/favicon.png"></menuitem>';
menu.firstElementChild.addEventListener('click', function() {
    GM_openInTab('http://www.instapaper.com/text?u=' + encodeURIComponent(location.href));
});
document.body.setAttribute('contextmenu', menu.id);

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 4:50 pm
by barbaz
https://noscript.net/faq#qa1_2

When it fails, do you see anything related in the Browser Console? (Ctrl-Shift-J)
When it fails, does it running any of the script at all? Try stuffing some alert()s or console.log()s in there to see where the script is getting.

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 6:14 pm
by Greg01010100
Hi, barbaz, and thanks for helping! :)

I tried script you shown but it didn't helped.

Script works and was tested to work when site is allowed. I used Browser Console on few sites and here is what i got:

Code: Select all

JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0

JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
lpmanuallogins.length is 0


JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
lpmanuallogins.length is 0
JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead ScriptSurrogate.js:302:145
lpmanuallogins.length is 0
lpmanuallogins.length is 0
Thanks again for any help. :)

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 6:21 pm
by barbaz
So nothing related errors... is that with site Allowed or Forbidden (or some of both)?

If you stick the line

Code: Select all

alert("Hi, I'm a running script!");
in various places in the code, do you ever get an alert? If so, at what point does it not fire (if any)? Does it fire outside the click event listener callback, what about inside?

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 7:12 pm
by Greg01010100
I tried adding that code you suggested and it fires only after I click button. Button doesn't even show itself in context menu till I allow site. Again thanks very much for taking time to help me. :)

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 8:14 pm
by barbaz
Greg01010100 wrote:Button doesn't even show itself in context menu till I allow site.
Ah. Does it work for you instead use GM_registerMenuCommand which puts the menu item in the user script menu instead the context menu?

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 8:59 pm
by Greg01010100
Yeh it works if i use GM_registerMenuCommand

Re: NoScript + Userscript Context Menu

Posted: Sat Apr 11, 2015 9:03 pm
by barbaz
Sounds like all there is to do is not use the page context menu... Wonder if page context menu works with NoScript disabled completely from Add-ons Manager, and JavaScript disabled by about:config > javascript.enabled set to false ?

Re: NoScript + Userscript Context Menu

Posted: Sun Apr 12, 2015 12:51 pm
by Greg01010100
No. If i disable NoScript and set javascript.enabled to false - context menu doesn't show up.........

Re: NoScript + Userscript Context Menu

Posted: Sun Apr 12, 2015 4:56 pm
by barbaz
Greg01010100 wrote:No. If i disable NoScript and set javascript.enabled to false - context menu doesn't show up.........
Thanks for testing that.
OK so not a NoScript issue, so the only way this will work with NoScript is if Giorgio decides to add some kind of work-around code in NoScript.

Re: NoScript + Userscript Context Menu

Posted: Sun Apr 12, 2015 6:48 pm
by Greg01010100
Is there any way to notify him to consider extending userscript compatibility to make this work???

Re: NoScript + Userscript Context Menu

Posted: Sun Apr 12, 2015 7:34 pm
by barbaz
Note that it may not even be feasible, I said that only because Giorgio has added workarounds for these kinds of things before so it's not ruled out at this point.
Greg01010100 wrote:Is there any way to notify him to consider extending userscript compatibility to make this work???
If he doesn't respond in a week or so, if you like I'll do some testing and maybe PM him?