Skip to content

Commit

Permalink
Add button to go to old reddit if new reddit is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoNezd committed Mar 24, 2024
1 parent 88a4397 commit ddeda15
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/css/redditChanges.css
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,18 @@ body.prevent-scroll {
.search-submit-button {
width: 50px;
}

.switch-to-good-reddit {
display: block;
position: fixed;
bottom: 0;
left: 0;
background-color: #ff4500;
color: white;
z-index: 9999999999;
font-size: large;
font-weight: bolder;
text-transform: uppercase;
pointer-events: all;
padding: 3px;
}
2 changes: 2 additions & 0 deletions src/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import RESCompatibility from "./RESCompatibility";
import PostsEnhancements from "./posts";
import { OLFeature } from "./base";
import WhiteTheme from "./themeSwitch";
import RedesignRedirect from "./redesignRedirect";
type Constructor = new (...args: any[]) => OLFeature;
const features: Array<Constructor> = [
Expandos,
Expand All @@ -14,6 +15,7 @@ const features: Array<Constructor> = [
RESCompatibility,
RedditMarquee,
WhiteTheme,
RedesignRedirect,
];
features.push(...PostsEnhancements);
export default features;
34 changes: 34 additions & 0 deletions src/features/redesignRedirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import querySelectorAsync from "../utility/querySelectorAsync";
import { OLFeature } from "./base";
function replaceSubdomain(url: string, toSubdomain: string) {
const replace = "://" + toSubdomain + ".";

// Prepend http://
if (!/^\w*:\/\//.test(url)) {
url = "http://" + url;
}

// Check if we got a subdomain in url
if (url.match(/\.\w*\b/g)!.length > 1) {
return url.replace(/(:\/\/\w+\.)/, replace);
}

return url.replace(/:\/\/(\w*\.)/, `${replace}$1`);
}

export default class RedesignRedirect extends OLFeature {
moduleId = "redesignRedirect";
moduleName = "RedesignRedirect";
async init() {
await querySelectorAsync("body");
if (!document.documentElement.classList.contains("js")) {
document.documentElement.classList.add("new-reddit");
const goToOldReddit = document.createElement("a");
goToOldReddit.classList.add("switch-to-good-reddit");
goToOldReddit.innerText = "Go to old reddit";
console.log("swt", replaceSubdomain(window.location.href, "old"));
goToOldReddit.href = replaceSubdomain(window.location.href, "old");
document.body.appendChild(goToOldReddit);
}
}
}
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const manifest = {
permissions: ["storage"],
content_scripts: [
{
matches: ["*://old.reddit.com/*"],
matches: ["*://*.reddit.com/*", "*://reddit.com/*"],
js: ["./cs.js", "./vendors.js"],
run_at: "document_start",
},
Expand All @@ -72,7 +72,7 @@ const userScriptBanner = `// ==UserScript==
// @version ${fullVersion}
// @description Makes old reddit more usable on mobile devices.
// @author OctoNezd
// @match https://old.reddit.com/*
// @match https://reddit.com/*
// @icon https://raw.githubusercontent.com/OctoNezd/oldlander/main/icons/icon.png
// @grant GM.setValue
// @grant GM.getValue
Expand Down

2 comments on commit ddeda15

@artemvmin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this. Is there any plan to make auto-redirect an extension option?

@OctoNezd
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Please sign in to comment.