1

Q: Is it possible to write a command in that script which automatically saves the original address as a bookmark, in that folder, before redirecting me? I can't find such a command.

Background:

Pretty much new to programming. I'm a student with a broken arm. When I come across an interesting article behind a paywall, I just reload the page using the university's proxy. With one arm broken, I have to do everything with the other hand. So I wrote a javascript in tampermonkey (similar to greasemonkey) which rewrites the URL and loads that page.

To keep track of the articles I've read, I add the address to my bookmarks, in a folder called "Already Read".

Code so far: (No bookmark command yet.)

// ==UserScript==
// @name         Cat.
// @include      https://www.sciencedirect.com/science/article/*
// @grant        GM_setClipboard
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// ==/UserScript==

(function() {
    'use strict';
    var OldURL = location.href;
     //Saves current URL into a string, "OldURL"
    location.href = OldURL.replace('https://www','http://proxy.ub.umu.se/login?url=https://www');
     //replaces the ScienceDirect domain, replaces it with the university proxy, and loads that address.

Desired result: add current page to my bookmarks automatically.

Preferably in a given bookmark folder, but I'd be very grateful to just add the bookmark anywhere. (Having a broken arm is not fun, studying is my catharsis for dealing with the boredom, so I really need to get this.) ANY help would be greatly appreciated!

What I've tried:

I've tried most bookmark related JavaScript commands I could find. (That's how I figured out the rest of TamperMonkey's functions.) But none seem to work. I've also tried including the commands to allow TamperMonkey to run a script without safety restrictions, such as // @grant GM_deleteValue etc.

1 Answers1

2

No, a Tampermonkey/Greasemonkey script cannot add bookmarks because such scripts are unable to affect a browser's "chrome"(not Google) UI -- for good reason.

Theoretically, Tampermonkey could make bookmark(s) somewhat more accessible to Tampermonkey scripts but hasn't so far, and there hasn't been much (¿any?) demand for such a feature until now.

You can (probably/used-to-be-able-to) write a Firefox or Opera extension that does this.


Meanwhile, Tampermonkey can keep a list of rewritten URL's but that's a bit more involved to wrap a UI around.

First, use location.assign() instead of location.replace(), if you are not already. That way, most of such links will show as visited in your history and on any pages that haven't violated link UI.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Thanks, dude! But I figured out a workaround: The function "GM_openInTab" opens a url in a background tab. All I do now is push ctrl+D, ctrl+W. A one hand operation. It was the constant tabbing that was giving me problems. – Krister Johnson Apr 26 '19 at 18:01
  • Needs must when the Devil drives. Glad you got a workaround, @KristerJohnson. – Brock Adams Apr 26 '19 at 18:07