TamperMonkey可以创建书签吗? [英] Can TamperMonkey create a bookmark?

查看:90
本文介绍了TamperMonkey可以创建书签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:是否可以在该脚本中编写一条命令,该命令会在重定向我之前自动将原始地址另存为该文件夹中的书签.我找不到这样的命令.

背景:

编程的新手.我是一个断胳膊的学生.当我在付费专栏后面遇到有趣的文章时,我只是使用大学的代理重新加载页面.一只胳膊断了,我必须用另一只手做所有事情.因此,我用tampermonkey(类似于油脂猴子)编写了一个javascript,它重写了URL并加载了该页面.

要跟踪已读的文章,我将地址添加到书签的已读"文件夹中.

到目前为止的代码:(尚无书签命令.)

 //== UserScript ==//@name Cat.//@include https://www.sciencedirect.com/science/article/*//@grant GM_setClipboard//@grant GM_setValue//@grant GM_getValue//@grant GM_deleteValue//==/UserScript ==(功能() {使用严格";var OldURL = location.href;//将当前网址保存到字符串"OldURL"中location.href = OldURL.replace('https://www','http://proxy.ub.umu.se/login?url = https://www');//替换ScienceDirect域,将其替换为大学代理,然后加载该地址. 

所需结果:自动将当前页面添加到我的书签中.

最好在给定的书签文件夹中,但我非常感谢您可以将书签添加到任何位置.(断臂不好玩,学习是我应对无聊的宣泄,所以我真的需要得到它.)任何帮助将不胜感激!

我尝试过的事情:

我尝试了我能找到的大多数与书签相关的JavaScript命令.(这就是我找出TamperMonkey其余功能的方式.)但似乎没有一个起作用.我还尝试过包含允许TamperMonkey运行不受安全限制的脚本的命令,例如//@grant GM_deleteValue等.

解决方案

否,Tampermonkey/Greasemonkey脚本无法添加书签,因为此类脚本无法影响浏览器的"chrome" (不是Google)用户界面-有充分的理由.

从理论上讲,Tampermonkey可以使Tampermonkey脚本更容易访问书签(但到目前为止还没有,到目前为止,对这种功能的需求不多.

您可以(可能/将要使用)编写执行此操作的Firefox或Opera扩展程序.


同时,Tampermonkey可以保留一个重写URL的列表,但这要涉及到环绕UI的复杂性.

首先,如果尚未使用 location.assign()而不是 location.replace(),请使用.这样,大多数此类链接将在您的历史记录以及未违反链接用户界面的任何页面上显示为已访问.

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.

解决方案

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.

这篇关于TamperMonkey可以创建书签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆