Add to Obtainium for F-Droid

Shows an "Add to Obtainium" button on F-Droid app pages.

当前为 2025-05-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Add to Obtainium for F-Droid
  3. // @namespace https://naeembolchhi.github.io/
  4. // @version 0.2
  5. // @description Shows an "Add to Obtainium" button on F-Droid app pages.
  6. // @author NaeemBolchhi
  7. // @license GPL-3.0-or-later
  8. // @match http*://f-droid.org/*/packages/*/*
  9. // @match http*://cloudflare.f-droid.org/*/packages/*/*
  10. // @icon data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 300'%3E%3Cdefs%3E%3ClinearGradient id='a' x1='-464.57' x2='-402.59' y1='485.32' y2='413.87' gradientTransform='matrix(2.83 0 0 -2.83 1398.77 1413.1)' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%239b58dc'/%3E%3Cstop offset='1' stop-color='%23321c92'/%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath d='M204.93 285.91c-3.79-2.01-25.95-14.29-129.75-71.9-28.88-16.03-56.7-31.45-61.8-34.26C1.78 173.37 0 171.8 0 167.96c0-2.01 4.63-14.89 15.48-43.06 8.51-22.1 16.04-41.47 16.73-43.04 1.57-3.58 4.09-6.61 6.56-7.89 2.31-1.19 60.02-22.27 62.97-23 3.18-.78 5.92.72 7.54 4.14.78 1.64 4 10.1 7.17 18.81 3.17 8.71 7.88 21.58 10.48 28.6 5.95 16.1 6.17 18.38 2.03 20.82-1.1.65-8.23 3.45-15.86 6.22-7.63 2.77-14.9 5.65-16.17 6.39-2.92 1.7-3.36 4.33-1.08 6.44.91.84 15.57 9.2 32.59 18.59 47.56 26.23 44.92 25.04 48.09 21.62 1.55-1.68 29.97-73.94 31.6-80.37.7-2.74.62-3.13-.87-4.33-2.03-1.64-1.74-1.71-20.41 4.89-18.5 6.54-20.26 6.68-22.74 1.79-1.3-2.57-21.23-57.3-22.47-61.7-.8-2.85.18-5.55 2.58-7.13 1-.65 15.5-6.22 32.23-12.36 24.82-9.12 31.14-11.19 34.37-11.24 4.17-.07 4.71.22 81.09 42.48 5.29 2.93 8.12 6.01 8.12 8.86 0 1.13-18.94 51.37-42.09 111.64-32.65 85-42.5 109.94-43.92 111.2-2.43 2.13-4.41 2.04-9.06-.42Z' fill='url(%23a)'/%3E%3C/svg%3E
  11. // @require https://update.greasyfork.org/scripts/535813/1587919/20250412230923.js
  12. // @run-at document-idle
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. // SVG Icons
  17. const svgIcons = {
  18. "obtainium": `<svg id="obtainiumlogo" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 300 300"><defs><linearGradient id="a" x1="-464.57" x2="-402.59" y1="485.32" y2="413.87" gradientTransform="matrix(2.83 0 0 -2.83 1398.77 1413.1)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#9b58dc"/><stop offset="1" stop-color="#321c92"/></linearGradient></defs><path d="M204.93 285.91c-3.79-2.01-25.95-14.29-129.75-71.9-28.88-16.03-56.7-31.45-61.8-34.26C1.78 173.37 0 171.8 0 167.96c0-2.01 4.63-14.89 15.48-43.06 8.51-22.1 16.04-41.47 16.73-43.04 1.57-3.58 4.09-6.61 6.56-7.89 2.31-1.19 60.02-22.27 62.97-23 3.18-.78 5.92.72 7.54 4.14.78 1.64 4 10.1 7.17 18.81 3.17 8.71 7.88 21.58 10.48 28.6 5.95 16.1 6.17 18.38 2.03 20.82-1.1.65-8.23 3.45-15.86 6.22-7.63 2.77-14.9 5.65-16.17 6.39-2.92 1.7-3.36 4.33-1.08 6.44.91.84 15.57 9.2 32.59 18.59 47.56 26.23 44.92 25.04 48.09 21.62 1.55-1.68 29.97-73.94 31.6-80.37.7-2.74.62-3.13-.87-4.33-2.03-1.64-1.74-1.71-20.41 4.89-18.5 6.54-20.26 6.68-22.74 1.79-1.3-2.57-21.23-57.3-22.47-61.7-.8-2.85.18-5.55 2.58-7.13 1-.65 15.5-6.22 32.23-12.36 24.82-9.12 31.14-11.19 34.37-11.24 4.17-.07 4.71.22 81.09 42.48 5.29 2.93 8.12 6.01 8.12 8.86 0 1.13-18.94 51.37-42.09 111.64-32.65 85-42.5 109.94-43.92 111.2-2.43 2.13-4.41 2.04-9.06-.42Z" fill="url(#a)"/></svg>`,
  19. "qr": `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 300 300"><rect width="51.37" height="51.37" x="162.05" y="162.23" rx="25.69" ry="25.69"/><rect width="51.37" height="51.37" x="248.63" y="162.23" rx="25.69" ry="25.69"/><rect width="51.37" height="51.37" x="162.05" y="248.63" rx="25.69" ry="25.69"/><circle cx="231.02" cy="231.11" r="18.68"/><path d="M90.29 0H46.7C20.91 0 0 20.91 0 46.7v43.59c0 25.8 20.91 46.7 46.7 46.7h43.59c25.8 0 46.7-20.91 46.7-46.7V46.7C137 20.91 116.09 0 90.29 0Zm9.34 87.18c0 6.88-5.57 12.45-12.45 12.45H49.82c-6.88 0-12.45-5.57-12.45-12.45V49.82c0-6.88 5.57-12.45 12.45-12.45h37.36c6.88 0 12.45 5.57 12.45 12.45v37.36ZM90.29 163H46.7C20.9 163 0 183.91 0 209.7v43.59c0 25.8 20.91 46.7 46.7 46.7h43.59c25.8 0 46.7-20.91 46.7-46.7V209.7c0-25.8-20.91-46.7-46.7-46.7Zm9.34 87.18c0 6.88-5.57 12.45-12.45 12.45H49.82c-6.88 0-12.45-5.57-12.45-12.45v-37.36c0-6.88 5.57-12.45 12.45-12.45h37.36c6.88 0 12.45 5.57 12.45 12.45v37.36ZM253.3 0h-43.59c-25.8 0-46.7 20.91-46.7 46.7v43.59c0 25.8 20.91 46.7 46.7 46.7h43.59c25.8 0 46.7-20.91 46.7-46.7V46.7C300 20.9 279.09 0 253.3 0Zm9.34 87.18c0 6.88-5.57 12.45-12.45 12.45h-37.36c-6.88 0-12.45-5.57-12.45-12.45V49.82c0-6.88 5.57-12.45 12.45-12.45h37.36c6.88 0 12.45 5.57 12.45 12.45v37.36Z"/></svg>`,
  20. "copy": `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 300 300"><path d="M11.31 114.58C22.19 91.94 42.46 79.36 75 75.16c3.58-23.12 10.99-48.03 35.81-62.02C129.77 2.45 162.65-1.75 208.54.66c30.27 1.59 66.95 8.17 82.09 45.21 6.06 14.84 9.56 40.88 9.36 69.65-.21 29.27-4.33 55.18-11.02 69.32-10.87 22.94-31.21 35.67-63.91 39.91-3.63 23.95-11.4 49.64-38.23 63.25-14.33 7.27-39.9 11.64-70.15 11.97-1.23.01-2.45.02-3.67.02-27.62 0-52.48-3.47-67.01-9.4-21.33-8.7-34.66-24.89-40.74-49.51-7.49-30.29-8.24-96.77 6.05-126.52v.02Zm132.52 147.46c39.08-4.06 43.57-18.9 45.68-57.16 2.39-43.23-1.43-70.68-11.37-81.58-10.53-11.56-37.26-12.79-48.68-13.32-40.48-1.87-69.37 2.44-79.25 11.82-6.22 5.91-9.25 16.62-10.69 24.57-3.17 17.49-2.79 35.85-2.19 51.69.05 1.33.1 2.69.14 4.08.68 20.16 1.52 45.25 20.71 53.95 19.42 8.8 62.82 8.32 85.62 5.95h.03ZM112.54 73.13l24.94.57.26.02c20.04 1.91 37.92 4.28 53.83 13.95 33.83 20.56 34.61 63.71 35.24 98.39 0 .48.02.96.03 1.44 15.71-2.68 26.51-8.32 31.61-24.91 7.06-22.99 6.69-79.29-.67-100.4-4.23-12.14-11.15-18-25.52-21.61-10.93-2.74-28.18-4.21-45.69-4.21-20.89 0-42.15 2.09-53.44 6.62-13.25 5.32-18.04 15.51-20.59 30.15Z"/></svg>`
  21. };
  22.  
  23. // Button Style
  24. const buttonStyle = `
  25. body .site-title {
  26. width: fit-content;
  27. }
  28. body > .site-wrapper {
  29. position: relative;
  30. }
  31. #obtainButton a {
  32. color: inherit;
  33. text-decoration: none;
  34. opacity: 1;
  35. }
  36. #obtainButton * {
  37. transition: transform .05s linear, border-radius .05s linear;
  38. }
  39. #obtainButton {
  40. position: absolute;
  41. right: 2rem;
  42. margin-top: .75rem .5rem .5rem .5rem;
  43. z-index: 999;
  44. -webkit-user-select: none;
  45. -ms-user-select: none;
  46. user-select: none;
  47. display: flex;
  48. justify-content: flex-end;
  49. transition: top .15s linear;
  50. top: -3.5rem;
  51. }
  52. #obtainButton.visible {
  53. top: 0;
  54. }
  55. #obtainButton .obtain-fixed {
  56. position: fixed;
  57. display: flex;
  58. align-items: center;
  59. justify-content: center;
  60. }
  61. #obtainButton .obtain-main svg {
  62. height: 2rem;
  63. width: 2rem;
  64. }
  65. #obtainButton .obtain-main {
  66. padding: .85rem .75rem .5rem .75rem;
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. gap: .5rem;
  71. height: 2.25rem;
  72. background: #ebe1ff;
  73. transform: translateY(-.35rem);
  74. border-radius: 0 0 0 .5rem;
  75. cursor: pointer;
  76. }
  77. #obtainButton .obtain-text {
  78. display: flex;
  79. flex-direction: column;
  80. line-height: 1;
  81. font-family: inherit;
  82. }
  83. #obtainButton .obtain-qr,
  84. #obtainButton .obtain-copy {
  85. padding: .85rem .5rem .5rem .5rem;
  86. display: flex;
  87. align-items: center;
  88. justify-content: center;
  89. height: 2.25rem;
  90. width: 2.25rem;
  91. transform: translateY(-.35rem);
  92. border-radius: 0 0 .5rem 0;
  93. cursor: pointer;
  94. background: #9B58DC;
  95. background: linear-gradient(113deg, rgba(155, 88, 220, 1) 0%, rgba(50, 28, 146, 1) 100%);
  96. fill: #ffffff;
  97. }
  98. #obtainButton .obtain-copy {
  99. --_bg-color: #242424;
  100. border-radius: 0 0 0 0;
  101. background: var(--_bg-color);
  102. }
  103. #obtainButton .obtain-main:active,
  104. #obtainButton .obtain-qr:active,
  105. #obtainButton .obtain-copy:active {
  106. transform: translateY(0);
  107. border-radius: 0 0 .5rem .5rem;
  108. }
  109. #obtainButton .obtain-qr svg,
  110. #obtainButton .obtain-copy svg {
  111. height: 1.75rem;
  112. width: 1.75rem;
  113. }
  114. #obtainButton .obtain-small {
  115. font-size: .8rem;
  116. }
  117. #obtainButton .obtain-large {
  118. font-size: 1.2rem;
  119. font-weight: 700;
  120. }
  121. #obtainButton #obtain-qr-display {
  122. position: fixed;
  123. top: 4rem;
  124. border-radius: .5rem;
  125. overflow: hidden;
  126. background: #fefefe;
  127. display: none;
  128. height: 0;
  129. max-height: 0;
  130. overflow: hidden;
  131. transition: height .1s ease-in-out, max-height .1s ease-in-out;
  132. box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 2px 6px 2px;
  133. }
  134. #obtainButton #obtain-qr-display img {
  135. margin: .75rem;
  136. width: 40rem;
  137. max-width: calc(100svw - 3.5rem);
  138. aspect-ratio: 1/1;
  139. }
  140. #obtainButton #obtain-qr-display.visible {
  141. display: block;
  142. }
  143. #obtainButton #obtain-qr-display.visible.animate {
  144. height: calc(40rem + .75rem + .75rem);
  145. max-height: calc(100svw - 3.5rem + .75rem + .75rem);
  146. }
  147. @media screen and (max-width: 750px) {
  148. #obtainButton {
  149. right: 1rem;
  150. }
  151. #obtainButton .obtain-fixed .obtain-text {
  152. display: none;
  153. }
  154. }
  155. `;
  156.  
  157. // Generate Obtainium Import Link
  158. function obtainiumLink() {
  159. const appName = document.querySelector('h3.package-name').textContent.replace(/[\t\n]/g,''),
  160. appID = window.location.pathname.replace(/.*packages\/(.*)\//,'$1'),
  161. appURL = window.location.href.replace(/\/$/,'');
  162.  
  163. const settingsJSON = `
  164. {
  165. "filterVersionsByRegEx": "",
  166. "trySelectingSuggestedVersionCode": true,
  167. "autoSelectHighestVersionCode": false,
  168. "trackOnly": false,
  169. "versionExtractionRegEx": "",
  170. "matchGroupToUse": "",
  171. "versionDetection": true,
  172. "useVersionCodeAsOSVersion": false,
  173. "apkFilterRegEx": "",
  174. "invertAPKFilter": false,
  175. "autoApkFilterByArch": true,
  176. "appName": "replacethiswithappnamelater",
  177. "appAuthor": "",
  178. "shizukuPretendToBeGooglePlay": false,
  179. "allowInsecure": false,
  180. "exemptFromBackgroundUpdates": false,
  181. "skipUpdateNotifications": false,
  182. "about": "",
  183. "refreshBeforeDownload": false
  184. }
  185. `.replace(/[\s\n]/g,'').replace(/\"/g,'\\"');
  186.  
  187. const mainJSON = `
  188. {
  189. "id": "${appID}",
  190. "url": "${appURL}",
  191. "author": "replacethiswithauthornamelater",
  192. "name": "replacethiswithappnamelater",
  193. "preferredApkIndex": 0,
  194. "additionalSettings": "replacethiswithsettingslater",
  195. "overrideSource": "FDroid"
  196. }
  197. `.replace(/[\s\n]/g,'')
  198. .replace(/replacethiswithsettingslater/, settingsJSON)
  199. .replace(/replacethiswithauthornamelater/, 'F-Droid official')
  200. .replace(/replacethiswithappnamelater/g, appName);
  201.  
  202. // return `https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/${encodeURIComponent(mainJSON)}`;
  203. return `obtainium://app/${encodeURIComponent(mainJSON)}`;
  204. }
  205.  
  206. // Button Content
  207. const buttonContent = `
  208. <div class="obtain-fixed">
  209. <a href="${obtainiumLink()}" class="obtain-main">${svgIcons.obtainium}<div class="obtain-text"><span class="obtain-small">Add to</span><span class="obtain-large">Obtainium</span></div></a>
  210. <div class="obtain-copy">${svgIcons.copy}</div>
  211. <div class="obtain-qr">${svgIcons.qr}</div>
  212. </div>
  213. <div id="obtain-qr-display"></div>
  214. `;
  215.  
  216. // Add a button
  217. function addButton() {
  218. let obtain = document.createElement('obtain');
  219. obtain.innerHTML = `<style type="text/css">${buttonStyle}</style>${buttonContent}`;
  220. obtain.id = "obtainButton";
  221.  
  222. document.querySelector('body > .site-wrapper').appendChild(obtain);
  223.  
  224. setTimeout(() => {
  225. document.querySelector('#obtainButton').classList.add('visible');
  226. }, 10);
  227. }
  228.  
  229. // Generate and place QR
  230. function makeQR() {
  231. let qrlink = 'https://apps.obtainium.imranr.dev/redirect?r=' + obtainiumLink();
  232. let target = document.querySelector('#obtain-qr-display');
  233.  
  234. doqr(qrlink, 1, "#fefefe", "#000000", target);
  235. }
  236.  
  237. // Copy function
  238. function copyString(string) {
  239. let copyButton = document.querySelector('.obtain-copy');
  240.  
  241. navigator.clipboard.writeText(string)
  242. .then(() => {
  243. // success
  244. copyButton.setAttribute('style','--_bg-color: #4caf50');
  245. })
  246. .catch(() => {
  247. // failure
  248. copyButton.setAttribute('style','--_bg-color: #f44336');
  249. });
  250.  
  251. setTimeout(() => {
  252. copyButton.removeAttribute('style');
  253. }, 800);
  254. }
  255.  
  256. // Event listeners
  257. function listenClick() {
  258. document.addEventListener('click', (e) => {
  259. let qrButton = document.querySelector('.obtain-qr'),
  260. qrImage = document.querySelector('#obtain-qr-display'),
  261. copyButton = document.querySelector('.obtain-copy')
  262.  
  263. if (qrButton.contains(e.target) && !qrImage.classList.contains('visible')) {
  264. qrImage.classList.add('visible');
  265. setTimeout(() => {
  266. qrImage.classList.add('animate');
  267. }, 10);
  268. } else if (qrButton.contains(e.target) && qrImage.classList.contains('visible')) {
  269. qrImage.classList.remove('animate');
  270. setTimeout(() => {
  271. qrImage.classList.remove('visible');
  272. }, 100);
  273. } else if (!qrImage.contains(e.target) && qrImage.classList.contains('visible')) {
  274. qrImage.classList.remove('animate');
  275. setTimeout(() => {
  276. qrImage.classList.remove('visible');
  277. }, 100);
  278. }
  279.  
  280. if (copyButton.contains(e.target)) {
  281. copyString('https://apps.obtainium.imranr.dev/redirect?r=' + obtainiumLink());
  282. }
  283. });
  284. }
  285.  
  286. addButton();
  287. makeQR();
  288. listenClick();