Last active
September 9, 2022 14:04
-
-
Save ivan/a5401be457b7c15648105694310b11ce to your computer and use it in GitHub Desktop.
A userscript to replace the incorrect "follow" language on inoreader with "subscribe"
This file contains hidden or 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
| // ==UserScript== | |
| // @name inoreader: we subscribe to RSS feeds; we do not follow them | |
| // @namespace inoreader_subscribe | |
| // @include https://www.inoreader.com/* | |
| // @version 1 | |
| // ==/UserScript== | |
| // Based on https://dev.to/kevin940726/one-fun-trick-to-observe-elements-in-realtime-without-mutationobserver-22kj | |
| function queryElements(selector, callback) { | |
| const elements = document.querySelectorAll(selector); | |
| elements.forEach(element => callback(element)); | |
| } | |
| function observe(selectors, callback) { | |
| for (let selector of selectors) { | |
| // Call it once for elements present before MutationObserver | |
| queryElements(selector, callback); | |
| } | |
| const observer = new MutationObserver(() => { | |
| for (let selector of selectors) { | |
| queryElements(selector, callback); | |
| } | |
| }); | |
| observer.observe(document.documentElement, { | |
| //attributes: true, | |
| childList: true, | |
| //characterData: true, | |
| subtree: true, | |
| }); | |
| } | |
| const selectors = [ | |
| // Blue "Follow" buttons | |
| 'button.bluebutton[onclick*="add_subscription("]', | |
| // "Unfollow" in the menu for a feed | |
| // "Unfollow all" in the menu for a feed folder | |
| 'div.inno_toolbar_button_menu_item', | |
| // Modal dialog after clicking Unsubscribe | |
| 'div#xconfirm', | |
| // Modal dialog after clicking Feed Properties | |
| 'button.redbutton', | |
| 'div.feed_info_dialog_header_info_meta_row', | |
| 'div.folder_dialog_line_header', | |
| // Temporary banner at the top of the viewport | |
| 'div.bn_text', | |
| // "Track keyword mentions across your followed feeds or all public articles." | |
| // on https://www.inoreader.com/monitored_keywords via "Monitored keywords" in the sidebar | |
| 'div.graylink', | |
| // https://www.inoreader.com/apps | |
| 'div.apps_heading', | |
| 'a.bookmark_link', | |
| // "Recommended sources", the right sidebar on https://www.inoreader.com/dashboard | |
| 'span.discover_feed_kpi_item_first', | |
| ]; | |
| observe(selectors, element => { | |
| switch (element.tagName) { | |
| case "BUTTON": | |
| if (element.innerText == "Follow") { | |
| element.innerText = "Subscribe"; | |
| } else if (element.innerText == "Unfollow") { | |
| element.innerText = "Unsubscribe"; | |
| } | |
| break; | |
| case "DIV": | |
| const classList = element.classList; | |
| if (classList.contains("inno_toolbar_button_menu_item")) { | |
| if (element.innerText == "Unfollow") { | |
| element.innerText = "Unsubscribe"; | |
| } else if (element.innerText == "Unfollow all") { | |
| element.innerText = "Unsubscribe from all"; | |
| } | |
| } else if (classList.contains("bn_text") && element.firstChild?.textContent.startsWith("Followed ")) { | |
| element.firstChild.textContent = element.firstChild.textContent.replace("Followed ", "Subscribed to "); | |
| } else if (classList.contains("graylink") && element.firstChild?.textContent.includes(" followed ")) { | |
| element.firstChild.textContent = element.firstChild.textContent.replace(" followed ", " subscribed "); | |
| } else if (classList.contains("apps_heading") && element.firstChild?.textContent.includes("Follow ")) { | |
| element.firstChild.textContent = element.firstChild.textContent.replace("Follow ", "Subscribe "); | |
| } else if (classList.contains("feed_info_dialog_header_info_meta_row") && element.firstChild?.textContent.includes("Date followed: ")) { | |
| element.firstChild.textContent = element.firstChild.textContent.replace("Date followed: ", "Date subscribed: "); | |
| } else if (classList.contains("folder_dialog_line_header") && element.firstChild?.textContent.includes("Followers:")) { | |
| element.firstChild.textContent = element.firstChild.textContent.replace("Followers:", "Subscribers:"); | |
| } else if (element.id == "xconfirm" && element.firstChild?.textContent == "Do you want to unfollow this feed?") { | |
| element.firstChild.textContent = "Do you want to unsubscribe from this feed?"; | |
| } | |
| break; | |
| case "A": | |
| if (element.classList.contains("bookmark_link") && element.innerText == "Follow in Inoreader") { | |
| element.innerText = "Subscribe in Inoreader"; | |
| } | |
| break; | |
| case "SPAN": | |
| if (element.classList.contains("discover_feed_kpi_item_first") && element.innerText.endsWith(" followers")) { | |
| element.innerText = element.innerText.replace(" followers", " subscribers"); | |
| } | |
| break; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment