Rearrange Links on animestars.org

Располагает ссылки в заданном порядке на странице animestars.org и заменяет ссылку на "Моя коллекция" на "Ответы на вопросы" с новой иконкой. Меняет расположение оставленных комментариев по клику на div ваших комментов. Кнопка коллекций на главной странице перекидывает на коллекции. Добавляет ссылку на Промокоды. Добавлены специфические размеры для ПК и телефонов.

目前为 2024-10-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Rearrange Links on animestars.org
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.7
  5. // @description Располагает ссылки в заданном порядке на странице animestars.org и заменяет ссылку на "Моя коллекция" на "Ответы на вопросы" с новой иконкой. Меняет расположение оставленных комментариев по клику на div ваших комментов. Кнопка коллекций на главной странице перекидывает на коллекции. Добавляет ссылку на Промокоды. Добавлены специфические размеры для ПК и телефонов.
  6. // @author eretly
  7. // @icon https://animestars.org/favicon.ico
  8. // @match https://animestars.org/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function getElementByXpath(path) {
  17. return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  18. }
  19.  
  20. function generateLinkXPath(number) {
  21. return `/html/body/div[2]/ul/li[${number}]/a`;
  22. }
  23.  
  24. let linksToSwap = [3, 2, 5, 6, 7, 10, 9, 4, 8, 1, 11];
  25. let originalLinks = [];
  26.  
  27. for (let i = 1; i <= 11; i++) {
  28. let linkXPath = generateLinkXPath(i);
  29. let linkElement = getElementByXpath(linkXPath);
  30. if (linkElement) {
  31. originalLinks.push(linkElement);
  32. }
  33. }
  34.  
  35. const headerElement = document.querySelector('header');
  36.  
  37. const linkElement = Array.from(headerElement.querySelectorAll('a')).find(link => link.href.match(/https:\/\/animestars\.org\/user\/(.+)\/$/));
  38.  
  39. if (linkElement) {
  40. const oldHref = linkElement.href;
  41.  
  42. const usernameMatch = oldHref.match(/https:\/\/animestars\.org\/user\/(.+)\/$/);
  43.  
  44. if (usernameMatch) {
  45. const username = usernameMatch[1];
  46. linkElement.href = `https://animestars.org/user/${username}/watchlist/`;
  47. }
  48. }
  49.  
  50.  
  51. const myListsLinkXPath = '/html/body/div[2]/ul/li[6]/a';
  52. const myListsLink = getElementByXpath(myListsLinkXPath);
  53.  
  54. if (myListsLink) {
  55. myListsLink.childNodes[1].textContent = "Мои списки";
  56. }
  57.  
  58. const collectionLinkXPath = generateLinkXPath(10);
  59. const collectionLink = getElementByXpath(collectionLinkXPath);
  60.  
  61. if (collectionLink) {
  62. collectionLink.outerHTML = `
  63. <a href="https://animestars.org/faq/" style="display: flex; flex-direction: column; justify-content: center; align-items: center; border-radius: 6px; padding: 8.3px; text-align: center; white-space: nowrap; background-color: var(--ui-bg-darker); box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1); font-size: 13px; color: var(--tt); text-decoration: none; transition: all .3s; height: 100%; position: relative;">
  64. <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 14 14" class="fal" style="opacity: 0.27; position: absolute; top: 8px;">
  65. <circle cx="7" cy="7" r="6.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
  66. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M5.5 5.5A1.5 1.5 0 1 1 7 7v1"/>
  67. <path fill="currentColor" d="M7 9.5a.75.75 0 1 0 .75.75A.76.76 0 0 0 7 9.5Z"/>
  68. </svg>
  69. <span style="margin-top: 30px;">Ответы на вопросы</span>
  70. </a>`;
  71. }
  72.  
  73. const promoCodeLinkXPath = '/html/body/div[1]/div/footer/a[1]';
  74. const promoCodeLink = getElementByXpath(promoCodeLinkXPath);
  75.  
  76. if (promoCodeLink) {
  77. promoCodeLink.href = "https://animestars.org/promo_codes";
  78. promoCodeLink.textContent = "Промокоды";
  79. }
  80.  
  81. const noLabelElements = document.querySelectorAll('.usp__list .no-label');
  82. noLabelElements.forEach(element => {
  83. element.style.display = 'none';
  84. });
  85.  
  86. const commentsLinkXPath = '//*[@id="userinfo"]/div[1]/div/ul[2]/li/a';
  87. const commentsLink = getElementByXpath(commentsLinkXPath);
  88.  
  89. const commentsContainerUserinfoXPath = '//*[@id="userinfo"]/div[1]/div/div[2]/div/div[3]';
  90. const commentsContainerUserinfo = getElementByXpath(commentsContainerUserinfoXPath);
  91.  
  92. const commentsContainerDleContentXPath = '//*[@id="dle-content"]/div[1]/div/div[2]/div/div[3]';
  93. const commentsContainerDleContent = getElementByXpath(commentsContainerDleContentXPath);
  94.  
  95. const commentsLinkDleContentXPath = '//*[@id="dle-content"]/div[1]/div/ul[2]/li/a';
  96. const commentsLinkDleContent = getElementByXpath(commentsLinkDleContentXPath);
  97.  
  98. function addLinkToContainer(container, link) {
  99. if (container && link) {
  100. const commentsLinkWrapper = document.createElement('a');
  101. commentsLinkWrapper.href = link.href;
  102. commentsLinkWrapper.style.position = "absolute";
  103. commentsLinkWrapper.style.width = "100%";
  104. commentsLinkWrapper.style.height = "100%";
  105. commentsLinkWrapper.style.top = "0";
  106. commentsLinkWrapper.style.left = "0";
  107. commentsLinkWrapper.style.cursor = "pointer";
  108. commentsLinkWrapper.style.borderRadius = "5px";
  109. commentsLinkWrapper.style.backgroundColor = "transparent";
  110. commentsLinkWrapper.style.display = "flex";
  111. commentsLinkWrapper.style.justifyContent = "center";
  112. commentsLinkWrapper.style.alignItems = "center";
  113.  
  114. container.style.position = "relative";
  115.  
  116. if (!container.querySelector('a[href*="lastcomments"]')) {
  117. container.appendChild(commentsLinkWrapper);
  118. }
  119. }
  120. }
  121.  
  122. addLinkToContainer(commentsContainerUserinfo, commentsLink);
  123. addLinkToContainer(commentsContainerDleContent, commentsLinkDleContent);
  124.  
  125. const style = document.createElement('style');
  126. style.textContent = `
  127. .login__menu a {
  128. min-width: 105px;
  129. }
  130.  
  131. @media (max-width: 768px) {
  132. .login__menu {
  133. display: flex;
  134. flex-wrap: wrap;
  135. gap: 0px;
  136. }
  137. .login__menu a {
  138. flex-basis: calc(50% - 1px);
  139. justify-content: center;
  140. box-sizing: border-box;
  141. }
  142. .login__menu a:last-child:nth-child(odd) {
  143. flex-basis: 100%;
  144. }
  145. }
  146.  
  147. a:hover, a:focus {
  148. color: #9e294f !important;
  149. text-decoration: none !important;
  150. }
  151.  
  152. a[style*="Ответы на вопросы"]:hover {
  153. color: #9e294f !important;
  154. text-decoration: none !important;
  155. }
  156. `;
  157. document.head.appendChild(style);
  158.  
  159. linksToSwap.forEach((newPosition, index) => {
  160. let parent = originalLinks[index].parentNode;
  161. if (originalLinks[newPosition - 1] && parent) {
  162. parent.replaceChild(originalLinks[newPosition - 1].cloneNode(true), originalLinks[index]);
  163. }
  164. });
  165.  
  166. })();