我写了一个脚本,该脚本当前在页面加载时在GreaseMonkey中工作。但是,当我将此脚本转移到TamperMonkey(在Chrome中)时,该脚本拒绝在Page Load上运行。
请参阅脚本:
// ==UserScript==
// @name Redirect_ADFS
// @author Eskimonian
// @version 2018.08.20
// @description Auto Redirect ADFS Sites to Internal Login Page
// @run-at document-end
// ==/UserScript==
window.onload = function Redirect() {
var currenturl = window.location.href //define current URL
if(currenturl.indexOf("/adfs") > -1) {
var newurl = "//" + new URL(document.referrer).hostname + '/admin?saml=off'; //set destination URL
alert("[Eskimo.1] SAML Site Detected. Redirecting to Internal Login page.")
window.location = newurl
}
} //redirect URL if the currently existing url contains "adfs" in its pathname
脚本的作用:
脚本在后台运行的示例:
转到:https://www.piercecountywa.gov/
输入/ admin:https://www.piercecountywa.gov/admin
重定向到:https://sas.co.pierce.wa.us/adfs/ls/
然后,我的脚本将强制页面呈现引荐网址,并将/ admin?saml = off添加到引荐字符串并重新加载页面
我的脚本进入:https://www.piercecountywa.gov/admin?saml=off
同样,在Greasemonkey中运行它仍然可以,但是-我不明白如何使它从Tampermonkey开始运行。
任何有助于理解为什么不起作用的帮助将不胜感激。
谢谢! 我知道这可能很难解决,因为您无法测试,因此以下是在Greasemonkey中工作的脚本的视频。
请注意从ADFS登录名立即重定向到内部登录名表单。
答案 0 :(得分:1)
在标题中,您使用的是@run-at document-start
,根据documentation,它将立即注入脚本。
尝试使用@run-at document-end
,它在调度DOMContentLoaded
事件时将注入脚本。如果您不走运,请尝试通过以下方式加入load
事件:
window.addEventListener("load", function(event) {
console.log("All resources finished loading!");
});