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.5
  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 = true
  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. - would be nice to replace the variable-based config with a key/value type deal with GM_setValue
  27. - add a ProtonDB button if the "released on" section doesn't include Linux
  28. - scrape the IGDB link to add a gog-games.to link if it exists
  29. - SteamRip link? Might be kinda redundant
  30. */
  31.  
  32. function removeTurbolinks() {
  33. if (location.host == 'backloggd.com') {
  34. document.querySelectorAll('a').forEach(link => {
  35. if (link.href.startsWith('https://backloggd.com')) {
  36. link.setAttribute('data-turbolinks', 'false');
  37. }
  38. });
  39. }
  40. }
  41.  
  42. // We have to get the game name and the right element from the IGDB link because Backloggd doesn't have any meaningful class names
  43. function changeIgdbUrl () {
  44. if (location.host == 'backloggd.com') {
  45. const link = document.querySelector('a[href^="https://www.igdb.com/games/"]')
  46. const linkElement = link.parentElement
  47.  
  48. if (linkElement) {
  49. let searchURL = getSearchUrl(link)
  50. linkElement.innerHTML = `Download on <a href="${searchURL}" target="_blank">cs.rin.ru</a>`
  51. }
  52. }
  53. }
  54.  
  55.  
  56. function getSearchUrl(link) {
  57. // examle IGDB link: https://backloggd.com/games/yakuza-6-the-song-of-life
  58. let searchQuery = link.href.split('/').pop()
  59. searchQuery = searchQuery.replaceAll('-', ' ')
  60. searchQuery = encodeURIComponent(searchQuery)
  61. 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'
  62. return searchURL
  63. }
  64.  
  65. function clickFirstRinLink() {
  66. let params = new URLSearchParams(document.location.search)
  67. // 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
  68. let scriptActive = params.get('backloggdrinscript');
  69. if (scriptActive) {
  70. const topics = document.querySelectorAll('a.topictitle');
  71.  
  72. // only redirect if there's one link in the search results
  73. if (topics.length === 1) {
  74. window.location.href = topics[0].href;
  75. }
  76. }
  77. }
  78.  
  79. if (disableTurbolinks === true) {
  80. removeTurbolinks()
  81. }
  82.  
  83. clickFirstRinLink()
  84.  
  85.  
  86. // Backloggd uses turbolinks, so we have to re-run each time the url changes
  87. // Will occasionally decide to not work. Refreshing fixes this but might be worth migrating to vm-url in case that works better
  88. // https://violentmonkey.github.io/api/matching/#matching-spa-sites-like-fb-github-twitter-youtube
  89. onUrlChange()
  90.  
  91. if (self.navigation && disableTurbolinks === false) {
  92. navigation.addEventListener('navigatesuccess', onUrlChange);
  93. } else {
  94. let u = location.href;
  95. new MutationObserver(() => u !== (u = location.href) && onUrlChange())
  96. .observe(document, {subtree: true, childList: true});
  97. }
  98.  
  99. function onUrlChange() {
  100. changeIgdbUrl()
  101. }