[英]How can I add a parameter to a URL and then reload the page using Greasemonkey?
如果您沒有登錄,Quora網站會將其大部分內容模糊不清。另一種方法是將參數“?share = 1”添加到其URL中。 我認為通過Greasemonkey執行此操作的步驟是:
0 /存儲當前URL
1 /檢查參數是否已經存在。 如果是,請休息。
2 /如果沒有,請添加參數。
3 /使用更新的URL重新加載。
它類似於這個問題,但在我看來,這可以在沒有正則表達式的情況下完成嗎? 我錯了。
這是我正在嘗試使用的代碼:
// ==UserScript==
// @name Quora Share
// @namespace kevmo.info
// @version 0.1
// @description adds "?share=1" to URLS, i.e. let's you view full Quora content w/o being logged in.
// @include https://*.quora.com/*
// @include http://*quora.com/*
// @copyright Creative Commons
// ==/UserScript==
var url = window.location.href;
if (url.indexOf("?share=1") !== -1){
break;
}
else{
url +="?share=1";
window.location.replace(url)
}
注意:在“settings”中,我將腳本設置為在document-start運行。
我知道這種基本方法不適用於其他網站,但只是附加“?share = 1” 應該適用於Quora(參見: http : //blog.quora.com/Making-Sharing-Better )
當我訪問http://www.quora.com/Animals/What-are-some-mind-blowing-facts-from-the-animal-kingdom時 ,頁面不會使用添加的參數重新加載所需的新URL。
元編輯:你正在使用“休息”; 而不是在循環結構中。
function share_redirect() {
var new_url = false;
if (window.location.hash.length === 0 && window.location.search.lenth === 0) {
new_url = window.location.href+"?share=1"
} else {
if (window.location.search.indexOf('share=1') != -1) {
return false; // already sharing
}
if (window.location.search.length && window.location.hash.length) {
new_url = window.location.href.split('#')[0]+"&share=1"+window.location.hash;
} else if (window.location.search.length === 0 && window.location.hash.length) {
new_url = window.location.href.split('#')[0]+"?share=1"+window.location.hash;
} else {
new_url = window.location.href+"&share=1";
}
}
if (new_url) {
window.location = new_url;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.