-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add button to go to old reddit if new reddit is detected
- Loading branch information
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ddeda15
There was a problem hiding this comment.
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?
ddeda15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes