Greasy Fork is available in English.

Discussions » Creation Requests

Help with small script :)

§
Posted: 09.04.2015

Help with small script :)

Hi, anyone could help me make this script:

Contextmenu entry that opens in current tab this - "http://www.instapaper.com/text?u=[current URL]"
Thanks! :D

wOxxOmMod
§
Posted: 09.04.2015

Userscript cannot add items to the context menu. The only way would be to display a small icon on hover so that when you click that icon it will open that url.

wOxxOmMod
§
Posted: 09.04.2015

Wow, another cool new feature of html5! And Firefox is pioneering the uncharted territory yet again.

// ==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="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(menu.url));
});

document.body.addEventListener('contextmenu', function(e) {
    menu.url = e.target.href;
    document.body.setAttribute('contextmenu', menu.url ? menu.id : null);
});
§
Posted: 10.04.2015

Hi I tried to run your script but it gives me this error:

Exception: TypeError: document.body is undefined
@Scratchpad/2:5:5
WCA_evalWithDebugger@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webconsole.js:1164:16
WCA_onEvaluateJS@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webconsole.js:786:20
WCA_onEvaluateJSAsync@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webconsole.js:757:20
DSC_onPacket@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/main.js:1422:15
LocalDebuggerTransport.prototype.send/<@resource://gre/modules/devtools/dbg-client.jsm -> resource://gre/modules/devtools/transport/transport.js:545:11
makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/DevToolsUtils.js:82:14
makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/DevToolsUtils.js:82:14
cmd_showItemPreferences_doCommand@chrome://mozapps/content/extensions/extensions.js:1075:9
gVC_doCommand@chrome://mozapps/content/extensions/extensions.js:1377:5
showPreferences@chrome://mozapps/content/extensions/extensions.xml:1562:11
oncommand@about:addons:1:1
*/

wOxxOmMod
§
Posted: 10.04.2015

What is your Greasemonkey version?
What site(s)?

§
Posted: 10.04.2015

I tried this site and few others, and Greasemonkey is latest version.......

wOxxOmMod
§
Posted: 10.04.2015

Using Greasemonkey 3.1 I've installed this script and had no such problem. Try adding // @run-at document-end on a new line before // ==/UserScript==

§
Posted: 10.04.2015

Well for some reason it simply doesn't show anything.... But thanks for help anyways!

wOxxOmMod
§
Posted: 10.04.2015

What element do you right click? The script adds the instapaper item only to links because it's the way I've interpreted [current URL] in your post.

§
Posted: 10.04.2015

I feel really stupid. Sorry your script works fine, but could you make it for current tab, not links? Thanks :)

wOxxOmMod
§
Posted: 10.04.2015
// ==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);
§
Posted: 11.04.2015
Edited: 11.04.2015

Thanks your script works great, if I don't use context menu editor like:

https://addons.mozilla.org/en-US/firefox/addon/s3menu-wizard/?src=search

http://menueditor.mozdev.org/

Is there way to make this work with them?

P.S And it only works if I allow site with noscript.........

wOxxOmMod
§
Posted: 11.04.2015
Edited: 11.04.2015

Well, this is a script so naturally it's affected by NoScript but the addon has many options and maybe you can find a way to whitelist the script. Also try Menu Filter addon, maybe it's more compatible. Anyway there's nothing that I can do about the issue. If nothing helps, your only option is to use an addon like Custom Buttons to create a custom toolbar button or keyconfig to create a hotkey with the script code. You can also try notifying the developers of NoScript and Menu Wizard of the problem.

§
Posted: 11.04.2015

Well menu filter works fine. As for noscript - I have no idea how to allow this script, it doesn't show on sites allowed......

wOxxOmMod
§
Posted: 11.04.2015

BTW I'm using uBlock instead of NoScript, it's more than enough for my needs.

§
Posted: 11.04.2015

uBlock is ad blocker or it also block scripts as in NoScript?

wOxxOmMod
§
Posted: 11.04.2015

Yes, in the advanced mode.

Post reply

Sign in to post a reply.