A script for Violentmonkey to automatically add something to the end of all wikia URLs?
Recently Wikia/Fandom has released a new design for their site that looks absolutely dreadful and they're slowly forcing it as the default skin for all of their wikis. Users can still log in and select the Oasis skin but this only changes the appearance of the site as long as they're logged in. The moment the user logs out, or if they're just looking at a wiki with no need to sign in, they're stuck using the new design. This can easily be remedied by adding ?useskin=oasis to the end of a Wikia page's URL, but it has to be done every time you go to a new page.
I need a script for Violentmonkey/Tampermonkey that will automatically add ?useskin=oasis to the end of all wikia URLs so that I can use the Oasis skin even while I'm not logged in.
I've tried modifying the old Youtube Polymer Disable script as it performed a similar action but it didn't work. And I've tried this, which adds ?useskin=oasis to the url but keeps adding it repeatedly and reloading the page.
// ==UserScript==
// @name Oasis Wikia
// @match *://*.fandom.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
var oldUrlPath = window.location.pathname;
*/
if ( ! /\?useskin=oasis$/.test (oldUrlPath) ) {
var newURL = window.location.protocol + "//"
+ window.location.host
+ oldUrlPath + "?useskin=oasis"
+ window.location.search
+ window.location.hash
;
/*-- replace() puts the good page in the history instead of the
bad page.
*/
window.location.replace (newURL);
}
window.location.pathname does not include the query string, so you got yourself an endless loop there.
Is a USVString containing an initial '/' followed by the path of the URL, not including the query string or fragment.
var oldUrlPath = window.location.pathname;
! /\?useskin=oasis$/.test (oldUrlPath)
will never find what you are looking for. You could check location.search instead and then rebuild the URL if needed. Also note that if the URL you are converting does already contain a query string, this will cause trouble
+ window.location.pathname + "?useskin=oasis"
+ window.location.search
because you will have 2 ? in your resulting new URL then. If you want to keep the old query string, be aware of that, or just drop it outright.
This should work
// ==UserScript==
// @name Oasis Wikia
// @match *://*.fandom.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
if ( ! /useskin=oasis/.test(window.location.search) ) {
var newURL = window.location.protocol + "//"
+ window.location.host
+ window.location.pathname + "?useskin=oasis"
+ window.location.search.replace('?', '&')
+ window.location.hash;
/*-- replace() puts the good page in the history instead of the
bad page.
*/
window.location.replace (newURL);
}