InoReader replace comss.ru domain with comss.one

Replaces comss.ru links to comss.one for those who try to access comss.ru website from outside of Russian Federation

当前为 2024-04-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InoReader replace comss.ru domain with comss.one
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description Replaces comss.ru links to comss.one for those who try to access comss.ru website from outside of Russian Federation
  6. // @author Kenya-West
  7. // @match https://*.inoreader.com/feed*
  8. // @match https://*.inoreader.com/article*
  9. // @match https://*.inoreader.com/folder*
  10. // @match https://*.inoreader.com/starred*
  11. // @match https://*.inoreader.com/library*
  12. // @match https://*.inoreader.com/channel*
  13. // @match https://*.inoreader.com/teams*
  14. // @match https://*.inoreader.com/dashboard*
  15. // @match https://*.inoreader.com/pocket*
  16. // @icon https://inoreader.com/favicon.ico?v=8
  17. // @license MIT
  18. // ==/UserScript==
  19. // @ts-check
  20.  
  21. (function () {
  22. "use strict";
  23.  
  24. const appConfig = {
  25. corsProxy: "https://corsproxy.io/?",
  26. };
  27.  
  28. const appState = {
  29. readerPaneExists: false,
  30. };
  31.  
  32. // Select the node that will be observed for mutations
  33. const targetNode = document.body;
  34.  
  35. // Options for the observer (which mutations to observe)
  36. const mutationObserverGlobalConfig = {
  37. attributes: false,
  38. childList: true,
  39. subtree: true,
  40. };
  41.  
  42. const querySelectorPathArticleRoot =
  43. ".article_full_contents .article_content";
  44.  
  45. /**
  46. * Callback function to execute when mutations are observed
  47. * @param {MutationRecord[]} mutationsList - List of mutations observed
  48. * @param {MutationObserver} observer - The MutationObserver instance
  49. */
  50. const callback = function (mutationsList, observer) {
  51. for (let mutation of mutationsList) {
  52. if (mutation.type === "childList") {
  53. mutation.addedNodes.forEach(function (node) {
  54. if (node.nodeType === Node.ELEMENT_NODE) {
  55. replaceLinksInArticleList(node);
  56. replaceLinksInArticleView(node);
  57. }
  58. });
  59. }
  60. }
  61. };
  62.  
  63. //
  64. //
  65. // FIRST PART - RESTORE IMAGES IN ARTICLE LIST
  66. //
  67. //
  68. //
  69.  
  70. /**
  71. *
  72. * @param {Node} node
  73. * @returns {void}
  74. */
  75. function replaceLinksInArticleList(node) {
  76. const readerPane = document.body.querySelector("#reader_pane");
  77. if (readerPane) {
  78. if (!appState.readerPaneExists) {
  79. appState.readerPaneExists = true;
  80.  
  81. /**
  82. * Callback function to execute when mutations are observed
  83. * @param {MutationRecord[]} mutationsList - List of mutations observed
  84. * @param {MutationObserver} observer - The MutationObserver instance
  85. */
  86. const callback = function (mutationsList, observer) {
  87. for (let mutation of mutationsList) {
  88. if (mutation.type === "childList") {
  89. mutation.addedNodes.forEach(function (node) {
  90. if (node.nodeType === Node.ELEMENT_NODE) {
  91. if (appState.readerPaneExists) {
  92. setTimeout(() => {
  93. start(node);
  94. }, 500);
  95. }
  96. }
  97. });
  98. }
  99. }
  100. };
  101.  
  102. // Options for the observer (which mutations to observe)
  103. const mutationObserverLocalConfig = {
  104. attributes: false,
  105. childList: true,
  106. subtree: false,
  107. };
  108.  
  109. // Create an observer instance linked to the callback function
  110. const tmObserverArticleList = new MutationObserver(callback);
  111.  
  112. // Start observing the target node for configured mutations
  113. tmObserverArticleList.observe(
  114. readerPane,
  115. mutationObserverLocalConfig
  116. );
  117. }
  118. } else {
  119. appState.readerPaneExists = false;
  120. }
  121.  
  122. /**
  123. *
  124. * @param {Node} node
  125. */
  126. function start(node) {
  127. readerPane
  128. ?.querySelectorAll("[href*='comss.ru']")
  129. .forEach((link) => {
  130. if (!link) {
  131. return;
  132. }
  133. const href = link.getAttribute("href");
  134. const newHref = href?.replace("comss.ru", "comss.one");
  135. if (!newHref) {
  136. return;
  137. }
  138. link.setAttribute("href", newHref);
  139. });
  140. }
  141. }
  142.  
  143. //
  144. //
  145. // SECOND PART - RESTORE IMAGES IN ARTICLE VIEW
  146. //
  147. //
  148. //
  149.  
  150. /**
  151. *
  152. * @param {Node} node
  153. * @returns {void}
  154. */
  155. function replaceLinksInArticleView(node) {
  156. /**
  157. * @type {HTMLDivElement | null}
  158. */
  159. const article = document.body.querySelector(".article_full_contents");
  160. if (article) {
  161. setTimeout(() => {
  162. start(article);
  163. }, 500);
  164. }
  165.  
  166. /**
  167. *
  168. * @param {HTMLDivElement} article
  169. */
  170. function start(article) {
  171. article
  172. ?.querySelectorAll("a[href*='comss.ru']")
  173. .forEach((link) => {
  174. if (!link) {
  175. return;
  176. }
  177. const href = link.getAttribute("href");
  178. const newHref = href?.replace("comss.ru", "comss.one");
  179. if (!newHref) {
  180. return;
  181. }
  182. link.setAttribute("href", newHref);
  183. });
  184. }
  185. }
  186.  
  187. // Create an observer instance linked to the callback function
  188. const tmObserverImageRestore = new MutationObserver(callback);
  189.  
  190. // Start observing the target node for configured mutations
  191. tmObserverImageRestore.observe(targetNode, mutationObserverGlobalConfig);
  192. })();