Skip to content

Instantly share code, notes, and snippets.

@corylulu
Last active November 12, 2017 15:29
Show Gist options
  • Save corylulu/d0125562c55f455b01d0ef4c9d928753 to your computer and use it in GitHub Desktop.
Save corylulu/d0125562c55f455b01d0ef4c9d928753 to your computer and use it in GitHub Desktop.
Disable new Profiles for Reddit
// ==UserScript==
// @name Disable New Profiles
// @namespace http://tampermonkey.net/
// @version 1.1.1
// @description Modifies all profile links to bring you to the overview page by default. Also adds an "Overview" tab to the new Profile page and a "Profile" tab to the overview page.
// @author /u/corylulu
// @match https://www.reddit.com/*
// @grant none
// @require https://raw.githubusercontent.com/uzairfarooq/arrive/master/minified/arrive.min.js
// ==/UserScript==
(function() {
'use strict';
function modifyLink(a){
if(a && a.href) {
if (a.href.match(/\/u(?:ser)?\/[^\/?]+\/?$/) && a.className != "ignoreModifyLink")
a.href = a.href + (a.href.endsWith("/") ? "overview" : "/overview");
}
}
function addOverviewTab(tabMenu) {
if(tabMenu) {
var overview = document.createElement("a");
overview.href = document.location.href.replace(/(.*\/u(?:ser)?\/[^\/?]+).*/, "$1") + "/overview";
overview.className = "TabMenu__tab";
overview.innerText = "Overview";
tabMenu.append(overview);
}
}
function addProfileTab() {
var tabMenu = document.getElementsByClassName("tabmenu");
if(tabMenu && tabMenu.length > 0) {
var tabLI = document.createElement("li");
var tabA = document.createElement("a");
tabA.href = "./";
tabA.className = "ignoreModifyLink";
tabA.innerText = "profile";
tabLI.append(tabA);
tabMenu[0].insertBefore(tabLI, tabMenu[0].firstChild);
}
}
// Adds Overview tab to new Profile pages (identified by lack of jQuery)
if (!window.jQuery && document.location.href.match(/\/u(?:ser)?\/[^\/?]+\/?$/)) {
var tabMenu = document.getElementsByClassName("TabMenu");
if(tabMenu.length > 0) {
addOverviewTab(tabMenu[0]);
} else {
document.arrive('.TabMenu', function(){ addOverviewTab(this); });
}
}
// Add profile link to profile pages, only if they have an upgraded profile.
else if(document.location.href.match(/\/u(?:ser)?\/.+\/(?:overview|submitted|gilded|upvoted|downvoted|hidden|saved)/) && r.config.post_site.startsWith("u_")) {
addProfileTab();
}
// Modifies all existing links
var links = document.getElementsByTagName("a");
for(var i in links) {
modifyLink(links[i]);
}
// Modifies links dynamically added to page
document.arrive('a', function(){ modifyLink(this); });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment