aboutsummaryrefslogtreecommitdiff
path: root/youtube/piped-button.user.js
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2024-11-17 22:36:53 -0600
committerTim Keller <tjkeller.xyz>2024-11-17 22:36:53 -0600
commit6bb49cc16cbf03d4e0980c2343372ff20d0a4b55 (patch)
tree38b659a6081e639cce5bd4503886370a75c5c770 /youtube/piped-button.user.js
parentd7484069764fe74654fe5e7721919462bc1286d2 (diff)
downloaduserscripts-6bb49cc16cbf03d4e0980c2343372ff20d0a4b55.tar.xz
userscripts-6bb49cc16cbf03d4e0980c2343372ff20d0a4b55.zip
rename all scripts to have .user.js ext
Diffstat (limited to 'youtube/piped-button.user.js')
-rw-r--r--youtube/piped-button.user.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/youtube/piped-button.user.js b/youtube/piped-button.user.js
new file mode 100644
index 0000000..60cd7f2
--- /dev/null
+++ b/youtube/piped-button.user.js
@@ -0,0 +1,63 @@
+// ==UserScript==
+// @name Piped Button youtube.com
+// @namespace Violentmonkey Scripts
+// @match https://www.youtube.com/*
+// @grant GM_addStyle
+// @version 1.0
+// @author -
+// @description 3/9/2024, 8:38:47 PM
+// ==/UserScript==
+
+/* Config */
+const instanceHostname = "piped.tjkeller.xyz"
+const instanceProtocol = "https:"
+const instanceIconLogo = "/img/icons/logo.svg"
+
+const instanceUrl = `${instanceProtocol}//${instanceHostname}`
+
+const redirectButtonId = "piped-button"
+
+GM_addStyle(`
+ a#${redirectButtonId} button {
+ background-color: #272727;
+ border-radius: 18px;
+ border: none;
+ color: white;
+ cursor: pointer;
+ display: flex;
+ font-family: "Roboto","Arial",sans-serif;
+ font-weight: 500;
+ height: 36px;
+ padding: .25em 1em .25em .65em;
+ text-decoration: none;
+ }
+ a#${redirectButtonId} button:hover { background-color: #3f3f3f; }
+ a#${redirectButtonId} button * { align-self: center; max-height: 100%; }
+`)
+
+
+function newUrl() {
+ return `${instanceProtocol}//${instanceHostname}${document.location.pathname}${document.location.search}`
+}
+
+if (!document.getElementById(redirectButtonId)) {
+ const redirectButton = document.createElement("a")
+ const redirectButtonC = redirectButton.appendChild(document.createElement("button"))
+ const redirectButtonImg = redirectButtonC.appendChild(document.createElement("img"))
+ const redirectButtonTxt = redirectButtonC.appendChild(document.createElement("span"))
+ redirectButton.id = redirectButtonId
+ redirectButtonImg.src = instanceUrl + instanceIconLogo
+ redirectButtonImg.alt = "(Down)" // Logo effectively acts as a test to see whether the instance is up or not as a bonus
+ redirectButtonTxt.innerText = "Piped"
+
+ redirectButton.addEventListener("mouseover", () => { redirectButton.href = newUrl() })
+
+ /* Insert */
+ document.body.addEventListener("yt-navigate-finish", () => {
+
+ setTimeout(() => {
+ const headContainer = document.querySelector("#masthead-container #container #start")
+ headContainer.appendChild(redirectButton)
+ }, 500) // Wait 500ms for page load to finish after event called
+ })
+}