Replace IGDB with cs.rin.ru for Backloggd

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

目前为 2025-03-10 提交的版本,查看 最新版本

  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.2
  12. // @icon https://external-content.duckduckgo.com/ip3/www.backloggd.com.ico
  13. // @license GPLv3
  14. // ==/UserScript==
  15.  
  16. /*
  17. TODO:
  18. - 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
  19. - 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
  20. - add a ProtonDB button if the "released on" section doesn't include Linux
  21. - scrape the IGDB link to add a gog-games.to link if it exists
  22. - SteamRip link? Might be kinda redundant
  23. */
  24.  
  25. // We have to get the game name and the right element from the IGDB link because Backloggd doesn't have any meaningful class names
  26.  
  27. function changeIgdbUrl () {
  28. if (location.host == "backloggd.com") {
  29. const link = document.querySelector('a[href^="https://www.igdb.com/games/"]')
  30. const linkElement = link.parentElement
  31.  
  32. if (linkElement) {
  33. let searchURL = getSearchUrl(link)
  34. linkElement.innerHTML = `Download on <a href="${searchURL}" target="_blank">cs.rin.ru</a>`
  35. }
  36. }
  37. }
  38.  
  39.  
  40. function getSearchUrl(link) {
  41. // examle IGDB link: https://backloggd.com/games/yakuza-6-the-song-of-life
  42. let searchQuery = link.href.split('/').pop()
  43. searchQuery = searchQuery.replaceAll('-', ' ')
  44. searchQuery = encodeURIComponent(searchQuery)
  45. 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'
  46. return searchURL
  47. }
  48.  
  49. // Backloggd uses those weird SPA style links, so we have to re-run each time the url changes
  50. // Will occasionally decide to not work. Refresh fixes this but might be worth migrating to vm-url in case that works better
  51. // https://violentmonkey.github.io/api/matching/#matching-spa-sites-like-fb-github-twitter-youtube
  52. onUrlChange();
  53.  
  54. if (self.navigation) {
  55. navigation.addEventListener('navigatesuccess', onUrlChange);
  56. } else {
  57. let u = location.href;
  58. new MutationObserver(() => u !== (u = location.href) && onUrlChange())
  59. .observe(document, {subtree: true, childList: true});
  60. }
  61.  
  62. function onUrlChange() {
  63. changeIgdbUrl()
  64. }