Skip to content

Instantly share code, notes, and snippets.

@jdembowski
Last active May 21, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdembowski/c1e0df5d879c1bd4c7d967914d6e8b66 to your computer and use it in GitHub Desktop.
Save jdembowski/c1e0df5d879c1bd4c7d967914d6e8b66 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name WordPress topic redirect
// @namespace WordPress_topic_redirect
// @description Forces https, adds view=all to topic urls and redirects if needed.
// @version 1
// @grant none
// @run-at document-start
// @include *://*wordpress.org/support/topic/*
// @include https://wordpress.org/support/plugin/*
// @include https://wordpress.org/support/theme/*
// @include https://wordpress.org/support/users/*
// @include https://wordpress.org/support/forum/*
// ==/UserScript==
( function() {
var search = window.location.search;
var https_protocol = window.location.protocol.replace( /http\:/g, 'https:' );
var url = https_protocol + "//" + window.location.host + window.location.pathname;
var new_url = ( https_protocol != window.location.protocol ) ? url : false;
if ( search ) {
pattern = /view=all/g;
if ( !pattern.test( search ) ) {
new_url = ( ( new_url ) ? new_url : url ) + search + '&view=all';
}
} else {
new_url = ( ( new_url ) ? new_url : url ) + '?view=all';
}
if ( new_url ) {
window.location.replace( new_url + window.location.hash );
}
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment