I have written a script that is current working in GreaseMonkey on page load. However, when I transfer this script over to TamperMonkey (In Chrome), the Script refuses to run on Page Load.
See Script:
// ==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
What the script does:
Example with script running in background:
Go to: https://www.piercecountywa.gov/
Type /admin: https://www.piercecountywa.gov/admin
Redirects to: https://sas.co.pierce.wa.us/adfs/ls/
My script will then force the page to render the referral URL and add /admin?saml=off to the referral string and reload the page
My Script goes to: https://www.piercecountywa.gov/admin?saml=off
Again, running this in Greasemonkey works, however - I cannot understand how to make it run on start with Tampermonkey.
Any help on understanding WHY this is not working would be greatly appreciated.
Thank you! I understand this might be hard to troubleshoot as you cannot test so here is a video of the script working in Greasemonkey.
Note the immediate redirect from the ADFS login to the internal login form.