我已经为geocaching.com写了一个用户脚本,如果英语是由外部应用程序设置的,它会自动将语言切换到指定的语言(德语)。
它运行良好,直到大约10天前,没有任何原因,我无法想象。
如果我从脚本中删除@grant,它将再次工作,但会导致页面的其余部分出现几个问题。
我尝试过的任何@grant,包括none,都会破坏脚本。
它仍然可以在Chrome中正常工作。但是我已经听说了,Tampermonkey和Chrome和Firefox上的Greasemonkey有一点不同。
任何我可以尝试的想法都是非常受欢迎的。脚本如下:
// ==UserScript==
// @name c:geo LangFix Deutsch BETA
// @include https://www.geocaching.com/*/*/*
// @include https://www.geocaching.com/*/*
// @include https://www.geocaching.com/*
// @include https://www.geocaching.com
// @include http://www.geocaching.com/*/*/*
// @include http://www.geocaching.com/*/*
// @include http://www.geocaching.com/*
// @include http://www.geocaching.com
// @exclude http://www.geocaching.com/account/messagecenter
// @exclude https://www.geocaching.com/map/*
// @exclude https://www.geocaching.com/map
// @version 1.2
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
var TargetLink = $('a[href*="LocaleList$ctl04$uxLocaleItem"]');
var LanguageSwitch = $("div.LocaleText:contains('Choose Language')");
if (TargetLink.length && LanguageSwitch.length)
window.location.assign (TargetLink[0].href);发布于 2015-08-19 11:31:53
主要的问题是,脚本试图分配的href**,实际上是一个函数。**即:
TargetLink[0].href的值为javascript:__doPostBack('ctl00$uxLocaleList$uxLocaleList$ctl04$uxLocaleItem','')。
许多浏览器仍然允许你向location.assign()传递一个Firefox,但是javascript:最近限制了这种做法。(参见GM bug 2232、Firefox bug 1192821等)在沙箱中尤其如此(将@grant设置为none以外的值)。
更好的做法是使用,如下所示。
该脚本的其他小问题:
@include是重叠的、冗余的,并且可能会拖累性能。下面的@match语句应该是all you need.LocaleList$ctl04$uxLocaleItem这样的script.)@noframes来阻止它并加快速度。考虑到所有这些,这个完整的脚本应该比旧的脚本更适合您:
// ==UserScript==
// @name c:geo LangFix Deutsch BETA
// @match *://www.geocaching.com/*
// @exclude http://www.geocaching.com/account/messagecenter
// @exclude https://www.geocaching.com/map/*
// @version 2.0
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @noframes
// @grant GM_xmlhttpRequest
// ==/UserScript==
var EnglishPageIndicator = $(".selected-language > a:contains(English)");
if (EnglishPageIndicator.length) {
var GermanLnk = $(
".language-selector > .language-list > ul > li > a:contains(Deutsch)," +
".LocaleList > .language-list > li > a:contains(Deutsch)"
);
//-- Don't try to assign a JS location! Click the link instead.
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent ("click", true, true);
GermanLnk[0].dispatchEvent (clickEvent);
}https://stackoverflow.com/questions/32072520
复制相似问题