Add to Obtainium

Shows an "Add to Obtainium" button on various Obtainium-supported app websites.

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

  1. // ==UserScript==
  2. // @name Add to Obtainium
  3. // @namespace https://naeembolchhi.github.io/
  4. // @version 0.4
  5. // @description Shows an "Add to Obtainium" button on various Obtainium-supported app websites.
  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. // @match http*://www.apkmirror.com/apk/*/*
  11. // @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
  12. // @require https://update.greasyfork.org/scripts/535813/1589729/QR-Code-Generator.js
  13. // @run-at document-idle
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. // SVG Icons
  18. const svgIcons = {
  19. "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>`,
  20. "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>`,
  21. "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>`
  22. };
  23.  
  24. // Conditional styles
  25. function styleIf() {
  26. let web = window.location.hostname;
  27.  
  28. if (web.match(/f.droid/)) {
  29. return ``;
  30. } else if (web.match(/apkmirror/)) {
  31. return `
  32. #masthead .site-toolbar .search-bar {
  33. margin-right: 28.5rem;
  34. }
  35. #obtainButton {
  36. right: calc(1.5 * var(--orem));
  37. }
  38. @media screen and (max-width: 991px) {
  39. .searchbox-parent.open {
  40. right: 300px;
  41. }
  42. }
  43. @media screen and (max-width: 750px) {
  44. #obtainButton {
  45. right: calc(1.25 * var(--orem));
  46. }
  47. #masthead .site-toolbar .search-bar {
  48. margin-right: 17.75rem;
  49. }
  50. .searchbox-parent.open {
  51. right: 190px;
  52. }
  53. }
  54. `;
  55. }
  56. }
  57.  
  58. // Button Style
  59. const buttonStyle = `
  60. :root {
  61. --orem: 16px;
  62. }
  63. body .site-title {
  64. width: fit-content;
  65. }
  66. body > .site-wrapper {
  67. position: relative;
  68. }
  69. #obtainButton a {
  70. color: inherit;
  71. text-decoration: none;
  72. opacity: 1;
  73. }
  74. #obtainButton * {
  75. box-sizing: content-box;
  76. transition: transform .05s linear, border-radius .05s linear;
  77. }
  78. #obtainButton {
  79. position: absolute;
  80. right: calc(2 * var(--orem));
  81. margin-top: calc(.75 * var(--orem)) calc(.5 * var(--orem)) calc(.5 * var(--orem)) calc(.5 * var(--orem));
  82. z-index: 999;
  83. -webkit-user-select: none;
  84. -ms-user-select: none;
  85. user-select: none;
  86. display: flex;
  87. justify-content: flex-end;
  88. transition: top .15s linear;
  89. top: calc(-3.5 * var(--orem));
  90. }
  91. #obtainButton.visible {
  92. top: 0;
  93. }
  94. #obtainButton .obtain-fixed {
  95. position: fixed;
  96. display: flex;
  97. align-items: center;
  98. justify-content: center;
  99. }
  100. #obtainButton .obtain-main svg {
  101. height: calc(2 * var(--orem));
  102. width: calc(2 * var(--orem));
  103. }
  104. #obtainButton .obtain-main {
  105. padding: calc(.85 * var(--orem)) calc(.75 * var(--orem)) calc(.5 * var(--orem)) calc(.75 * var(--orem));
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. gap: calc(.5 * var(--orem));
  110. height: calc(2.25 * var(--orem));
  111. background: #ebe1ff;
  112. transform: translateY(calc(-.35 * var(--orem)));
  113. border-radius: 0 0 0 calc(.5 * var(--orem));
  114. cursor: pointer;
  115. }
  116. #obtainButton .obtain-text {
  117. display: flex;
  118. flex-direction: column;
  119. line-height: 1;
  120. font-family: inherit;
  121. }
  122. #obtainButton .obtain-qr,
  123. #obtainButton .obtain-copy {
  124. padding: calc(.85 * var(--orem)) calc(.5 * var(--orem)) calc(.5 * var(--orem)) calc(.5 * var(--orem));
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. height: calc(2.25 * var(--orem));
  129. width: calc(2.25 * var(--orem));
  130. transform: translateY(calc(-.35 * var(--orem)));
  131. border-radius: 0 0 calc(.5 * var(--orem)) 0;
  132. cursor: pointer;
  133. background: #9B58DC;
  134. background: linear-gradient(113deg, rgba(155, 88, 220, 1) 0%, rgba(50, 28, 146, 1) 100%);
  135. fill: #ffffff;
  136. }
  137. #obtainButton .obtain-copy {
  138. --_bg-color: #242424;
  139. border-radius: 0 0 0 0;
  140. background: var(--_bg-color);
  141. }
  142. #obtainButton .obtain-main:active,
  143. #obtainButton .obtain-qr:active,
  144. #obtainButton .obtain-copy:active {
  145. transform: translateY(0);
  146. border-radius: 0 0 calc(.5 * var(--orem)) calc(.5 * var(--orem));
  147. }
  148. #obtainButton .obtain-qr svg,
  149. #obtainButton .obtain-copy svg {
  150. height: calc(1.75 * var(--orem));
  151. width: calc(1.75 * var(--orem));
  152. }
  153. #obtainButton .obtain-small {
  154. font-size: calc(.8 * var(--orem));
  155. }
  156. #obtainButton .obtain-large {
  157. font-size: calc(1.2 * var(--orem));
  158. font-weight: 700;
  159. }
  160. #obtainButton #obtain-qr-display {
  161. position: fixed;
  162. top: calc(4 * var(--orem));
  163. border-radius: calc(.5 * var(--orem));
  164. overflow: hidden;
  165. background: #fefefe;
  166. display: none;
  167. height: 0;
  168. max-height: 0;
  169. overflow: hidden;
  170. transition: height .1s ease-in-out, max-height .1s ease-in-out;
  171. box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 2px 6px 2px;
  172. }
  173. #obtainButton #obtain-qr-display canvas {
  174. margin: calc(.75 * var(--orem));
  175. width: calc(40 * var(--orem));
  176. max-width: calc(100svw - (3.5 * var(--orem)));
  177. aspect-ratio: 1/1;
  178. }
  179. #obtainButton #obtain-qr-display img {
  180. display: none;
  181. }
  182. #obtainButton #obtain-qr-display.visible {
  183. display: block;
  184. }
  185. #obtainButton #obtain-qr-display.visible.animate {
  186. height: calc((40 * var(--orem)) + (.75 * var(--orem)) + (.75 * var(--orem)));
  187. max-height: calc(100svw - (3.5 * var(--orem)) + (.75 * var(--orem)) + (.75 * var(--orem)));
  188. }
  189. @media screen and (max-width: 750px) {
  190. #obtainButton {
  191. right: (1 * var(--orem));
  192. }
  193. #obtainButton .obtain-fixed .obtain-text {
  194. display: none;
  195. }
  196. }
  197. ` + styleIf();
  198.  
  199. // Generate F-Droid Link
  200. function fdroidLink() {
  201. const appName = document.querySelector('h3.package-name').textContent.replace(/[\t\n]/g,''),
  202. appID = window.location.pathname.replace(/.*packages\/(.*)\//,'$1'),
  203. appURL = window.location.href.replace(/\/$/,'');
  204.  
  205. const settingsJSON = `
  206. {
  207. "filterVersionsByRegEx": "",
  208. "trySelectingSuggestedVersionCode": true,
  209. "autoSelectHighestVersionCode": false,
  210. "trackOnly": false,
  211. "versionExtractionRegEx": "",
  212. "matchGroupToUse": "",
  213. "versionDetection": true,
  214. "useVersionCodeAsOSVersion": false,
  215. "apkFilterRegEx": "",
  216. "invertAPKFilter": false,
  217. "autoApkFilterByArch": true,
  218. "appName": "replacethiswithappnamelater",
  219. "appAuthor": "",
  220. "shizukuPretendToBeGooglePlay": false,
  221. "allowInsecure": false,
  222. "exemptFromBackgroundUpdates": false,
  223. "skipUpdateNotifications": false,
  224. "about": "",
  225. "refreshBeforeDownload": false
  226. }
  227. `.replace(/[\s\n]/g,'').replace(/\"/g,'\\"');
  228.  
  229. const mainJSON = `
  230. {
  231. "id": "${appID}",
  232. "url": "${appURL}",
  233. "author": "replacethiswithauthornamelater",
  234. "name": "replacethiswithappnamelater",
  235. "preferredApkIndex": 0,
  236. "additionalSettings": "replacethiswithsettingslater",
  237. "overrideSource": "FDroid"
  238. }
  239. `.replace(/[\s\n]/g,'')
  240. .replace(/replacethiswithsettingslater/, settingsJSON)
  241. .replace(/replacethiswithauthornamelater/, 'F-Droid official')
  242. .replace(/replacethiswithappnamelater/g, appName);
  243.  
  244. // return `https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/${encodeURIComponent(mainJSON)}`;
  245. return `obtainium://app/${encodeURIComponent(mainJSON)}`;
  246. }
  247.  
  248. // Generate APK Mirror Link
  249. function apkmirrorLink() {
  250. const appName = document.querySelector('.app-title').textContent,
  251. appAuthor = document.querySelector('.dev-title').textContent.replace(/^by\s/i,''),
  252. appID = document.querySelector('a[href*="play.google.com"]').href.replace(/.*id=/,'') || Date.now(),
  253. appURL = document.querySelectorAll('#breadcrumbs a')[1].href;
  254.  
  255. const settingsJSON = `
  256. {
  257. "fallbackToOlderReleases": true,
  258. "filterReleaseTitlesByRegEx": "",
  259. "trackOnly": true,
  260. "versionExtractionRegEx": "",
  261. "matchGroupToUse": "",
  262. "versionDetection": true,
  263. "releaseDateAsVersion": false,
  264. "useVersionCodeAsOSVersion": false,
  265. "apkFilterRegEx": "",
  266. "invertAPKFilter": false,
  267. "autoApkFilterByArch": true,
  268. "appName": "replacethiswithappnamelater",
  269. "appAuthor": "replacethiswithauthornamelater",
  270. "shizukuPretendToBeGooglePlay": false,
  271. "allowInsecure": false,
  272. "exemptFromBackgroundUpdates": false,
  273. "skipUpdateNotifications": false,
  274. "about": "",
  275. "refreshBeforeDownload": false
  276. }
  277. `.replace(/[\s\n]/g,'').replace(/\"/g,'\\"');
  278.  
  279. const mainJSON = `
  280. {
  281. "id": "${appID}",
  282. "url": "${appURL}",
  283. "author": "replacethiswithauthornamelater",
  284. "name": "replacethiswithappnamelater",
  285. "preferredApkIndex": 0,
  286. "additionalSettings": "replacethiswithsettingslater",
  287. "overrideSource": null
  288. }
  289. `.replace(/[\s\n]/g,'')
  290. .replace(/replacethiswithsettingslater/, settingsJSON)
  291. .replace(/replacethiswithauthornamelater/g, appAuthor)
  292. .replace(/replacethiswithappnamelater/g, appName);
  293.  
  294. // return `https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/${encodeURIComponent(mainJSON)}`;
  295. return `obtainium://app/${encodeURIComponent(mainJSON)}`;
  296. }
  297.  
  298. // Get right link for Obtainium
  299. function obtainiumLink() {
  300. let web = window.location.hostname;
  301.  
  302. if (web.match(/f.droid/)) {
  303. return fdroidLink();
  304. } else if (web.match(/apkmirror/)) {
  305. return apkmirrorLink();
  306. }
  307. }
  308.  
  309. // Button Content
  310. const buttonContent = `
  311. <div class="obtain-fixed">
  312. <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>
  313. <div class="obtain-copy">${svgIcons.copy}</div>
  314. <div class="obtain-qr">${svgIcons.qr}</div>
  315. </div>
  316. <div id="obtain-qr-display"></div>
  317. `;
  318.  
  319. // Add a button
  320. function addButton() {
  321. let obtain = document.createElement('obtain');
  322. obtain.innerHTML = `<style type="text/css">${buttonStyle}</style>${buttonContent}`;
  323. obtain.id = "obtainButton";
  324.  
  325. let web = window.location.hostname,
  326. buttonParent = 'body';
  327.  
  328. if (web.match(/f.droid/)) {
  329. buttonParent = 'body > .site-wrapper';
  330. } else if (web.match(/apkmirror/)) {
  331. buttonParent = 'body #masthead .site-toolbar';
  332. }
  333.  
  334. document.querySelector(buttonParent).appendChild(obtain);
  335.  
  336. setTimeout(() => {
  337. document.querySelector('#obtainButton').classList.add('visible');
  338. }, 10);
  339. }
  340.  
  341. // Generate and place QR
  342. function makeQR() {
  343. let qrlink = 'https://apps.obtainium.imranr.dev/redirect?r=' + obtainiumLink();
  344. let target = document.querySelector('#obtain-qr-display');
  345.  
  346. doqr(qrlink, 1, "#fefefe", "#000000", target);
  347. }
  348.  
  349. // Copy function
  350. function copyString(string) {
  351. let copyButton = document.querySelector('.obtain-copy');
  352.  
  353. navigator.clipboard.writeText(string)
  354. .then(() => {
  355. // success
  356. copyButton.setAttribute('style','--_bg-color: #4caf50');
  357. })
  358. .catch(() => {
  359. // failure
  360. copyButton.setAttribute('style','--_bg-color: #f44336');
  361. });
  362.  
  363. setTimeout(() => {
  364. copyButton.removeAttribute('style');
  365. }, 800);
  366. }
  367.  
  368. // Event listeners
  369. function listenClick() {
  370. document.addEventListener('click', (e) => {
  371. let qrButton = document.querySelector('.obtain-qr'),
  372. qrImage = document.querySelector('#obtain-qr-display'),
  373. copyButton = document.querySelector('.obtain-copy')
  374.  
  375. if (qrButton.contains(e.target) && !qrImage.classList.contains('visible')) {
  376. qrImage.classList.add('visible');
  377. setTimeout(() => {
  378. qrImage.classList.add('animate');
  379. }, 10);
  380. } else if (qrButton.contains(e.target) && qrImage.classList.contains('visible')) {
  381. qrImage.classList.remove('animate');
  382. setTimeout(() => {
  383. qrImage.classList.remove('visible');
  384. }, 100);
  385. } else if (!qrImage.contains(e.target) && qrImage.classList.contains('visible')) {
  386. qrImage.classList.remove('animate');
  387. setTimeout(() => {
  388. qrImage.classList.remove('visible');
  389. }, 100);
  390. }
  391.  
  392. if (copyButton.contains(e.target)) {
  393. copyString('https://apps.obtainium.imranr.dev/redirect?r=' + obtainiumLink());
  394. }
  395. });
  396. }
  397.  
  398. addButton();
  399. makeQR();
  400. listenClick();