Replace IGDB with cs.rin.ru for Backloggd

Replaces the IGDB button on Backloggd with a cs.rin.ru downolad link

目前為 2025-03-11 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Replace IGDB with cs.rin.ru for Backloggd
  3. // @description Replaces the IGDB button on Backloggd with a cs.rin.ru downolad link
  4. // @author Soap
  5. // @namespace soap.systems
  6. // @homepageURL https://soap.systems
  7. // @match *://backloggd.com/*
  8. // @match *://*.backloggd.com/*
  9. // @match *://cs.rin.ru/forum/search.php*
  10. // @grant none
  11. // @version 1.4
  12. // @icon https://external-content.duckduckgo.com/ip3/www.backloggd.com.ico
  13. // @license GPLv3
  14. // ==/UserScript==
  15.  
  16.  
  17. // OPTIONS:
  18. // disable turbolinks-style navigation. this might make the site feel slower (though, not any slower than a normal website)
  19. // but it fixes an issue where links sometimes won't change automatically without a refresh
  20. // DEFAULT: true
  21. const disableTurbolinks = false
  22. // note that when the script updates you will have to reconfigure any options. shouldn't update too often though.
  23.  
  24. /*
  25. TODO:
  26. - currently the script takes you to the search results. update it to check the results page, and if there's only one match result, open it automatically
  27. - maybe i could add a url parameter to the links opened by the script to make sure it doesn't interfere with normal use of the site
  28. - add a ProtonDB button if the "released on" section doesn't include Linux
  29. - scrape the IGDB link to add a gog-games.to link if it exists
  30. - SteamRip link? Might be kinda redundant
  31. */
  32.  
  33. function removeTurbolinks() {
  34. if (location.host == 'backloggd.com') {
  35. document.querySelectorAll('a').forEach(link => {
  36. if (link.href.startsWith('https://backloggd.com')) {
  37. link.setAttribute('data-turbolinks', 'false');
  38. }
  39. });
  40. }
  41. }
  42.  
  43. // We have to get the game name and the right element from the IGDB link because Backloggd doesn't have any meaningful class names
  44. function changeIgdbUrl () {
  45. if (location.host == 'backloggd.com') {
  46. const link = document.querySelector('a[href^="https://www.igdb.com/games/"]')
  47. const linkElement = link.parentElement
  48.  
  49. if (linkElement) {
  50. let searchURL = getSearchUrl(link)
  51. linkElement.innerHTML = `Download on <a href="${searchURL}" target="_blank">cs.rin.ru</a>`
  52. }
  53. }
  54. }
  55.  
  56.  
  57. function getSearchUrl(link) {
  58. // examle IGDB link: https://backloggd.com/games/yakuza-6-the-song-of-life
  59. let searchQuery = link.href.split('/').pop()
  60. searchQuery = searchQuery.replaceAll('-', ' ')
  61. searchQuery = encodeURIComponent(searchQuery)
  62. let searchURL = 'https://cs.rin.ru/forum/search.php?keywords=' + searchQuery + '&terms=all&author=&sc=1&sf=titleonly&sk=t&sd=d&sr=topics&st=0&ch=300&t=0&submit=Search&backloggdrinscript=true'
  63. return searchURL
  64. }
  65.  
  66. function clickFirstRinLink() {
  67. let params = new URLSearchParams(document.location.search)
  68. // There's a 'backloggdrinscript' parameter added to the end of the search URL so we can detect you got to the search page from the script
  69. let scriptActive = params.get('backloggdrinscript');
  70. if (scriptActive) {
  71. const topics = document.querySelectorAll('a.topictitle');
  72.  
  73. // only redirect if there's one link in the search results
  74. if (topics.length === 1) {
  75. window.location.href = topics[0].href;
  76. }
  77. }
  78. }
  79.  
  80. if (disableTurbolinks === true) {
  81. removeTurbolinks()
  82. }
  83.  
  84. clickFirstRinLink()
  85.  
  86.  
  87. // Backloggd uses turbolinks, so we have to re-run each time the url changes
  88. // Will occasionally decide to not work. Refreshing fixes this but might be worth migrating to vm-url in case that works better
  89. // https://violentmonkey.github.io/api/matching/#matching-spa-sites-like-fb-github-twitter-youtube
  90. onUrlChange()
  91.  
  92. if (self.navigation && disableTurbolinks === false) {
  93. navigation.addEventListener('navigatesuccess', onUrlChange);
  94. } else {
  95. let u = location.href;
  96. new MutationObserver(() => u !== (u = location.href) && onUrlChange())
  97. .observe(document, {subtree: true, childList: true});
  98. }
  99.  
  100. function onUrlChange() {
  101. changeIgdbUrl()
  102. }