GGn Reuploader

Upload torrents to the same group using an existing torrent's details

  1. // ==UserScript==
  2. // @name GGn Reuploader
  3. // @namespace none
  4. // @version 2
  5. // @description Upload torrents to the same group using an existing torrent's details
  6. // @author dullfool68, ingts
  7. // @match https://gazellegames.net/torrents.php?id=*
  8. // @match https://gazellegames.net/torrents.php?action=edit&id=*
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_deleteValue
  12. // @grant GM_openInTab
  13. // @require
  14. // ==/UserScript==
  15. if (window.location.pathname.includes("upload")) {
  16. const formData = JSON.parse(
  17. GM_getValue("data", null),
  18. )
  19. if (formData) {
  20. GM_deleteValue("data")
  21. const form = document.getElementById('upload_table')
  22. form.addEventListener('submit', () => {
  23. GM_setValue("new", 1)
  24. })
  25.  
  26. for (const [key, value] of Object.entries(formData)) {
  27. if (key === 'scan') {
  28. const radio = document.getElementById(`${value === '0' ? 'digital' : 'scan'}`)
  29. radio.checked = true
  30. radio.dispatchEvent(new Event('click'))
  31. continue
  32. }
  33. if (!value) continue
  34. const inputElement = form.querySelector(`[name=${key}]`)
  35.  
  36. if (inputElement.type === "checkbox") {
  37. inputElement.checked = true
  38. } else {
  39. inputElement.value = value
  40. }
  41. if (inputElement.onclick) inputElement.dispatchEvent(new Event('click'))
  42. if (inputElement.onchange) inputElement.dispatchEvent(new Event('change'))
  43. }
  44. document.getElementById('release_title').dispatchEvent(new Event('blur'))
  45. }
  46. } else if (window.location.pathname.includes("torrent")) {
  47. $("tr.group_torrent > td > span > a:last-child").after(function () {
  48. const torrentId = /id=([0-9]+)/.exec($(this).attr("href"))[1]
  49. const upload = $("<a/>", {
  50. text: "UL",
  51. click: () => handleUploadClick(torrentId),
  52. })
  53. return [document.createTextNode(" | "), upload]
  54. })
  55. if (GM_getValue("new", null)) {
  56. document.querySelector(`#torrent${GM_getValue("torrentId")}`).style.backgroundColor = '#70474e'
  57. }
  58. GM_deleteValue("new")
  59. GM_deleteValue("torrentId")
  60. }
  61.  
  62. async function getTorrentFormData(torrentId) {
  63. const text = await fetch(
  64. `https://gazellegames.net/torrents.php?action=edit&id=${torrentId}`,
  65. ).then((response) => response.text())
  66.  
  67. const doc = new DOMParser().parseFromString(text, "text/html")
  68. const formElement = doc.querySelector("form#upload_table")
  69.  
  70. if (!formElement) {
  71. return null
  72. }
  73.  
  74. const formData = new FormData(formElement)
  75. if (doc.getElementById('digital')?.checked) {
  76. formData.set('scan', '0')
  77. formData.delete('scan_dpi')
  78. }
  79. else if (doc.getElementById('scan')?.checked) {
  80. formData.set('scan', '1')
  81. }
  82. return formData
  83. }
  84.  
  85. async function handleUploadClick(torrentId) {
  86. GM_setValue("torrentId", torrentId)
  87.  
  88. const formData = await getTorrentFormData(torrentId)
  89. if (!formData) {
  90. console.error("Form Data was null.")
  91. return
  92. }
  93.  
  94. const FORM_KEYS = [
  95. "remaster",
  96. "release_title",
  97. "miscellaneous",
  98. "gamedox",
  99. "gamedoxvers",
  100. "scan",
  101. "scan_dpi",
  102. "other_dpi",
  103. "isbn",
  104. "region",
  105. "language",
  106. // "ripsrc", scene/other auto selected once title is set
  107. "remaster_year",
  108. "remaster_title",
  109. "format",
  110. "release_desc",
  111. "scan_ocr",
  112. "issue", // e-book
  113. "bitrate", // OST
  114. "other_bitrate", // OST
  115. ]
  116.  
  117. GM_setValue(
  118. "data",
  119. JSON.stringify(
  120. FORM_KEYS.reduce((acc, cur) => {
  121. acc[cur] = formData.get(cur)
  122. return acc
  123. }, {}),
  124. ),
  125. )
  126. GM_openInTab(`https://gazellegames.net/upload.php?groupid=${new URL(location.href).searchParams.get('id')}`, {active: true})
  127. }
  128.