Greasy Fork is available in English.

Copy SteamDB Changelog as BBcode

Adds a button to copy changelog

  1. // ==UserScript==
  2. // @name Copy SteamDB Changelog as BBcode
  3. // @namespace none
  4. // @version 4
  5. // @description Adds a button to copy changelog
  6. // @author ingts
  7. // @match https://steamdb.info/patchnotes/*
  8. // @grant GM_setClipboard
  9. // ==/UserScript==
  10.  
  11. function html2bb(str) {
  12. if (!str) return ""
  13. str = str.replace(/<li>\n<p>(.*)<\/p>\n<ul>/g, '$1') // dont bullet first parent of nested list
  14. str = str.replace(/<li>(.*)<\/li>/g, '$1')
  15. str = str.replace(/<li>\n<p><strong>(.*)<\/strong>\s*<\/p>\s*<\/li>/g, '[*][b]$1[/b]')
  16. str = str.replace(/< *br *\/*>/g, "\n\n") //*/
  17. str = str.replace(/<hr\n?>/g, "\n") //*/
  18. str = str.replace(/< *b *>/g, "[b]")
  19. str = str.replace(/< *\/ *b *>/g, "[/b]")
  20. str = str.replace(/< *u *>/g, "[u]")
  21. str = str.replace(/< *\/ *u *>/g, "[/u]")
  22. str = str.replace(/< *i *>/g, "[i]")
  23. str = str.replace(/< *\/ *i *>/g, "[/i]")
  24. str = str.replace(/< *strong *>/g, "[b]")
  25. str = str.replace(/< *\/ *strong *>/g, "[/b]")
  26. str = str.replace(/< *em *>/g, "[i]")
  27. str = str.replace(/< *\/ *em *>/g, "[/i]")
  28. str = str.replace(/<li>\n/g, "[*]")
  29. str = str.replace(/< *\/ *li *>/g, "")
  30. str = str.replace(/< *ul *class=\\*\"bb_ul\\*\" *>/g, "")
  31. str = str.replace(/< *\/ *ul *>/g, "")
  32. str = str.replace(/< *h2 *class=\"bb_tag\" *>/g, "\n[align=center][u][b]")
  33. str = str.replace(/< *h[12] *>/g, "\n[align=center][u][b]")
  34. str = str.replace(/< *\/ *h[12] *>/g, "[/b][/u][/align]\n")
  35. str = str.replace(/&quot;/g, "\"")
  36. str = str.replace(/&amp;/g, "&")
  37. str = str.replace(/< *img *src="([^"]*)".*>/g, "\n")
  38. str = str.replace(/< *a [^>]*>/g, "")
  39. str = str.replace(/< *\/ *a *>/g, "")
  40. str = str.replace(/< *p *>/g, "")
  41. str = str.replace(/< *\/ *p *>/g, "")
  42. str = str.replace(/“/g, "\"")
  43. str = str.replace(/”/g, "\"")
  44. str = str.replace(/ +/g, " ")
  45. str = str.replace(/\n +/g, "\n")
  46. str = str.replace(/\n\n\n+/gm, "\n\n")
  47. str = str.replace(/\[\/b]\[\/u]\[\/align]\n\n/g, "[/b][/u][/align]\n")
  48. str = str.replace(/\n\n\[\*]/g, "\n[*]")
  49. str = str.replace(/<ul>\n/g, '')
  50. str = str.replace(/<h\d.*>(.*?)<\/h\d>/g, '[b]$1[/b]')
  51. // str = str.replace(/\[*]\n/g, '[*]')
  52. str = str.replace(/<lite-youtube.*>.*<\/lite-youtube>\n?/gs, '')
  53. str = str.replace(/https:\/\/store.steampowered.com.*\n?\n?/g, '')
  54. return str
  55. }
  56.  
  57. const button = document.createElement('button')
  58. button.textContent = 'Copy changelog as BBcode'
  59. document.querySelector('.patchnotes-metadata').querySelector('.hint-with-octicon:nth-of-type(3)').after(button)
  60. button.addEventListener('click', () => {
  61. const patchnotes = document.querySelector('.patchnotes-official')
  62. GM_setClipboard('[hide=Changelog]' + html2bb(patchnotes.innerHTML) + '[/hide]')
  63. button.textContent = 'Copied'
  64. })