Black Belt

Find and display links inside a bar; Type of links: chat, contact, email, geo, magnet, media documents, metalinks, podcasts, syndication feeds, torrents and userscripts and wallets.

当前为 2023-05-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Black Belt
  3. // @author Schimon Jehudah, Adv.
  4. // @namespace i2p.schimon.blackbelt
  5. // @homepageURL https://greasyfork.org/en/scripts/466113-black-belt
  6. // @supportURL https://greasyfork.org/en/scripts/466113-black-belt/feedback
  7. // @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  8. // @license MIT; https://opensource.org/licenses/MIT
  9. // @description Find and display links inside a bar; Type of links: chat, contact, email, geo, magnet, media documents, metalinks, podcasts, syndication feeds, torrents and userscripts and wallets.
  10. // @include *
  11. // @version 23.05.27
  12. // @run-at document-end
  13. // @noframes
  14. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn6WLPC90ZXh0Pjwvc3ZnPg==
  15. // ==/UserScript==
  16.  
  17. // NOTE
  18. // Robe icons (Sauna pack) created by Freepik
  19. // https://www.flaticon.com/free-icon/robe_2520932
  20. // https://www.flaticon.com/authors/freepik
  21. // https://www.freepik.com/
  22.  
  23. // TODO
  24. //
  25. // 0) Bar like https://www.croxyproxy.com/
  26. //
  27. // 0) Decode string for magnet links
  28. // https://btdig.com/9fe6281eaf39f8bee656f27cacf48713c0608c3e/20-birds-&-animals-books-collection-pack-4
  29. //
  30. // 0) Tooltip
  31. // https://www.w3schools.com/howto/howto_css_tooltip.asp
  32. // or DIV on the middle or center of screen
  33. // https://web.archive.org/web/20050423235409/http://karmatics.com/aardvark/
  34. // https://css-tricks.com/quick-css-trick-how-to-center-an-object-exactly-in-the-center/
  35. //
  36. // 1) Brand: Access Bar, Alt Bar, Black Bar, Black Robe, Distribar, Distributed Bar, Distribution Bar, Easy Access Bar, Free Bar, Freenet Bar, Handler Bar, Harvest Bar, IETF Bar, IETF Black Bar, IETF ToolBar, Instant Media Bar, Media Bar, Power Bar, Power Download Bar, Reaping Bar, Simple Access Bar, Simple Bar, Super Bar
  37. //
  38. // 2) Recognize btih of 32 and convert it to 40
  39. //
  40. // 3) Check cache links for none 200 code
  41. // https://bookshelf.theanarchistlibrary.org/library/librarian-previous-announcements-en
  42. //
  43. // 4) FIXME feedx
  44. // http://freebase.be/db/software.rss.xml
  45. //
  46. // 5) Case insensitive (XPath)
  47. // String.prototype.toLowerCase()
  48. // See 'Magnet:' heperlink at https://ddosecrets.com/wiki/Rosatom
  49. // See getPathTo()
  50. //
  51. // 6) Fetch button (guess on demand) instead of auto-guess
  52. // Find file by Hash or ID (Hint: find duplicate chars/strings)
  53. //
  54. // 7) Display software for IPFS, GPS, Monero, RSS, SIP, Tribler, XMPP
  55. //
  56. // 8) Market diaspora*, Linux, Mastodon, ownCloud, RetroShare
  57. //
  58. // 9) TODO cancel *:after "open in new tab" https://cookidoo.thermomix.com/foundation/en-US
  59.  
  60. // 'pge,✉️,contact,Contact'
  61. const types = {
  62. "feed" : {
  63. "name" : "📰 Follow", //索 //參
  64. "description" : "🗞️ Subscribe to news feed", //🔔
  65. "alternate" : [
  66. "atom",
  67. "rss",
  68. "rdf",
  69. "stream",
  70. "feed",
  71. "feed+json"],
  72. "extension" : [
  73. ".atom",
  74. ".atom.php",
  75. ".atom.xml",
  76. ".rss",
  77. ".rss.php",
  78. ".rss.xml",
  79. ".rdf",
  80. ".rdf.php",
  81. ".rdf.xml"],
  82. "path" : [
  83. "/feed",
  84. "/feed/",
  85. ".feed.atom",
  86. ".feed.rss",
  87. ".feed.rdf",
  88. ".feed.json"],
  89. "uri" : [
  90. "feed:",
  91. "news:"]
  92. },
  93. "podcast" : {
  94. "name" : "🎙️ Podcast",
  95. "description" : "🎧 Subscribe to podcast channel",
  96. "uri" : ["itpc:"]
  97. },
  98. "asc" : {
  99. "name" : "🗝️ Key", // Additional Sense Code
  100. "description" : "🔐 Encryption key",
  101. "extension" : [
  102. "asc",
  103. ".asc.txt",
  104. ".gpg",
  105. ".gpg.txt",
  106. ".pgp",
  107. ".pgp.txt"]
  108. },
  109. "mail" : {
  110. "name" : "✉️ Email",
  111. "description" : "📮 Send an email message",
  112. "uri" : ["mailto:"]
  113. },
  114. "card" : {
  115. "name" : "🪪 Card",
  116. "description" : "📇 Virtual contact file",
  117. "extension" : [".vcard", ".vcf"]
  118. },
  119. "geo" : {
  120. "name" : "📍️ Location",
  121. "description" : "🗺️ Geographic coordinations",
  122. "extension" : [
  123. ".gpx",
  124. ".geojson",
  125. ".kml",
  126. ".kmx"],
  127. "uri" : [
  128. "geo:",
  129. "waze:"]
  130. },
  131. "telephone" : {
  132. "name" : "☎️ Call",
  133. "description" : "📞️ Telephone number",
  134. "uri" : ["tel:"]
  135. },
  136. "voip" : {
  137. "name" : "📞️ VoIP",
  138. "description" : "📞️ Voice over IP",
  139. "uri" : ["sip:",
  140. "weixin:",
  141. "skype:"]
  142. },
  143. "chat-cabal" : {
  144. "name" : "🔽 Cabal", //︾ //🔽 //⧩ //➤
  145. "description" : "💬 Chat securely over the Cabal network",
  146. "uri" : ["cabal:"]
  147. },
  148. "chat-irc" : {
  149. "name" : "🗨️ IRC",
  150. "description" : "💬 Internet Relay Chat",
  151. "uri" : ["irc:", "ircs:"]
  152. },
  153. "chat-matrix" : {
  154. "name" : "#️ matrix", //#️⃣️ //# //⌗ //濫
  155. "description" : "⚠️ <b>WARNING:</b> Compromised messagin system. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  156. "uri" : ["element:", "matrix:"],
  157. "web" : ["://matrix.to/"]
  158. },
  159. "chat-xmpp" : {
  160. "name" : "💡️ Jabber",
  161. "description" : "💬 Chat securely over the XMPP network",
  162. "web" : [
  163. "://i.kaidan.im",
  164. "://join.jabber.network/#",
  165. "://anonymous.cheogram.com",
  166. "://magicbroccoli.de/i/",
  167. "://webchat.disroot.org/#converse/room?jid=",
  168. "://xmpp.org/chat#converse/room?jid=",
  169. "://yaxim.org/chat/#converse/room?jid=",
  170. "://yax.im/i/"],
  171. // TODO handle ?join and ?message
  172. "uri" : ["xmpp:"]
  173. },
  174. "chat-te" : {
  175. "name" : "👁️‍🗨️️ Tencent",
  176. "description" : "⚠️ <b>WARNING:</b> This chat service logs your activities and conversations to its records and discloses them to governments legally and illegally. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  177. "uri" : ["tencent:"]
  178. },
  179. "chat-vi" : {
  180. "name" : "👁️‍🗨️️ Viber",
  181. "description" : "⚠️ <b>WARNING:</b> This chat service logs your activities and conversations to its records and discloses them to governments legally and illegally. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  182. "uri" : ["viber:"]
  183. },
  184. "chat-tg" : {
  185. "name" : "👁️‍🗨️️ Telegram",
  186. "description" : "⚠️ <b>WARNING:</b> This chat service logs your activities and conversations to its records and discloses them to governments legally and illegally. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  187. "web" : [
  188. "://t.me",
  189. "://telegram.me"],
  190. "uri" : ["tg:"]
  191. },
  192. "chat-di" : {
  193. "name" : "👁️‍🗨️️ Discord",
  194. "description" : "⚠️ <b>WARNING:</b> This chat service logs your activities and conversations to its records and discloses them to governments legally and illegally. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  195. "web" : [
  196. "://discord.com",
  197. "://discord.gg"]
  198. },
  199. "chat-wh" : {
  200. "name" : "👁️‍🗨️️ Whatsapp",
  201. "description" : "⚠️ <b>WARNING:</b> This chat service logs your activities and conversations to its records and discloses them to governments legally and illegally. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  202. "web" : [
  203. "://chat.whatsapp.com",
  204. "://wa.me",
  205. "://api.whatsapp.com/send?phone=",
  206. "://web.whatsapp.com/send?phone="],
  207. "uri" : ["whatsapp:"]
  208. },
  209. "chat-fa" : {
  210. "name" : "👁️‍🗨️️ Facebook",
  211. "description" : "⚠️ <b>WARNING:</b> This chat service logs your activities and conversations to its records and discloses them to governments legally and illegally. Try <a href='https://xmpp.org/software/clients/' style='color:#000'>Jabber/XMPP</a> instead, for true privacy.",
  212. "web" : [
  213. "://m.me"]
  214. },
  215. "tracker" : {
  216. "name" : "📶 Tracker",
  217. "description" : "🧲 BitTorrent tracker",
  218. "uri" : ["udp:"]
  219. },
  220. "ftl-adc" : {
  221. "name" : "🫐️ DC", // Advanced Direct Connect
  222. "description" : "🧲 File transfer (magnet link)",
  223. "urn" : ['tree:tiger'],
  224. "uri" : [
  225. "adc:",
  226. "adcs:",
  227. "dchub:"]
  228. },
  229. "ftl-bitprint" : {
  230. "name" : "🪩 Gnutella2",
  231. "description" : "🧲 File transfer (magnet link)",
  232. "urn" : ["bitprint"]
  233. },
  234. "ftl-bittorrent" : {
  235. "name" : "🌊️ BitTorrent", //💧️ //⛲️
  236. "description" : "🧲 File transfer (magnet link)",
  237. "urn" : ["btih", "btmh"]
  238. },
  239. "ftl-torrent" : {
  240. "name" : "📦️ Torrent", //🧧️ //🎁️
  241. "description" : "⛲️ BitTorrent metadata file",
  242. "extension" : [".torrent"]
  243. },
  244. "ftl-ed2k" : {
  245. "name" : "♈ eDonkey",
  246. "description" : "🧲 File transfer (magnet link)", // eDonkey2000
  247. "uri" : ["ed2k:"],
  248. "urn" : [
  249. "aich",
  250. "ed2k",
  251. "ed2khash"]
  252. },
  253. "ftl-frostwire" : {
  254. "name" : "❄️ Frostwire", // LimeWire
  255. "description" : "🧲 File transfer (magnet link)",
  256. "urn" : ["sha1"]
  257. },
  258. "ftl-kazzaa" : {
  259. "name" : "⏭️ Fasttrack",
  260. "description" : "🧲 File transfer (magnet link)",
  261. "urn" : ["kzhash"]
  262. },
  263. "ftl-metalink" : {
  264. "name" : "♾️ Metalink",
  265. "description" : "♾️ Metalink file",
  266. "extension" : [".meta4", ".metalink"]
  267. },
  268. "ftl-shareaza" : {
  269. "name" : "❤️‍🔥️ Shareaza",
  270. "description" : "🧲 File transfer (magnet link)",
  271. "urn" : ["md5"]
  272. },
  273. "wallet-monero" : {
  274. "name" : "🪙️ Monero",
  275. "description" : "👛 Cryptocurrency wallet",
  276. "uri" : ["monero:"]
  277. },
  278. "wallet-litecoin" : {
  279. "name" : "🪙️ Litecoin",
  280. "description" : "👛 Cryptocurrency wallet",
  281. "uri" : ["litecoin:"]
  282. },
  283. "wallet-ethereum" : {
  284. "name" : "🪙️ Ethereum",
  285. "description" : "👛 Cryptocurrency wallet",
  286. "uri" : ["ethereum:"]
  287. },
  288. "wallet-bitcoin" : {
  289. "name" : "🪙️ Bitcoin",
  290. "description" : "👛 Cryptocurrency wallet",
  291. "uri" : ["bitcoin:"]
  292. },
  293. "pkg-apk" : {
  294. "name" : "💿 Package",
  295. "description" : "📦️ Android package",
  296. "condition" : ["android"],
  297. "extension" : ["apk"],
  298. "web" : [
  299. "://f-droid.org/packages/",
  300. "://apt.izzysoft.de/fdroid/index/apk/",
  301. "://mysu.dev/fdroid/",
  302. "://acruexirfkgcqhwxyu75v7dtahr3a44hmbfygngsvubmkrbd6axa.b32.i2p/fdroid/",
  303. "://cookiejarapps.com/fdroid/repo/",
  304. "://appgallery.huawei.com/app/",
  305. "://apkpure.com",
  306. "://play.google.com/store/apps/details?id="]
  307. },
  308. "pkg-appstream" : {
  309. "name" : "💿 Package",
  310. "description" : "🛍️ AppStream package",
  311. "condition" : ["linux"],
  312. "uri" : ["appstream:"]
  313. },
  314. "pkg-debian" : {
  315. "name" : "💿 Package",
  316. "description" : "🐧️ Debian package",
  317. "condition" : ["debian", "ubuntu"],
  318. "extension" : [".deb"]
  319. },
  320. "pkg-fedora" : {
  321. "name" : "💿 Package",
  322. "description" : "🐧️ Linux package",
  323. "condition" : ["fedora", "redhat"],
  324. "extension" : [".rpm"]
  325. },
  326. "pkg-flatpak" : {
  327. "name" : "💿 Package",
  328. "description" : "🧊 Flatpak package",
  329. "condition" : ["linux"],
  330. "extension" : [".flatpakref"],
  331. "web" : ["://flathub.org/apps/details/"]
  332. },
  333. "ios-pkg" : {
  334. "name" : "💿 Package",
  335. "description" : "📦️ iOS package",
  336. "condition" : ["ios", "iphone", "ipad"],
  337. "web" : ["://apps.apple.com/app/",
  338. "://apps.apple.com/us/app/"]
  339. },
  340. "pkg-kaios" : {
  341. "name" : "💿 Package",
  342. "description" : "📦️ Kai OS package",
  343. "condition" : ["kai"],
  344. "web" : ["://store.bananahackers.net/",
  345. "://www.kaiostech.com/store/apps/"]
  346. },
  347. "pkg-kde" : {
  348. "name" : "💿 Package",
  349. "description" : "🐲️ KDE package",
  350. "condition" : ["linux", "react", "windows"],
  351. "web" : ["://store.kde.org/p/"]
  352. },
  353. "pkg-mac" : {
  354. "name" : "💿 Package",
  355. "description" : "🍎️ Macintosh package",
  356. "condition" : ["mac"],
  357. "extension" : [",dmg", ".pkg"],
  358. "urn" : [""]
  359. },
  360. // NOTE WineHQ
  361. "pkg-reactos" : {
  362. "name" : "💿 Package",
  363. "description" : "⚛ <a href='https://reactos.org/' style='color:#000'>React OS</a> (Windows) package",
  364. "condition" : ["windows", "react"],
  365. "extension" : [".exe", ".msi"],
  366. "web" : ["://apps.microsoft.com/store/detail/",
  367. "://www.microsoft.com/store/apps/"]
  368. },
  369. // TODO ask snapcraft for path /app/
  370. // TODO Dismiss path root /
  371. "pkg-snapcraft" : {
  372. "name" : "💿 Snapcraft", // 📥️ // 🛍️
  373. "description" : "🪶️ Snapcraft package",
  374. "web" : ["://snapcraft.io/"]
  375. },
  376. "pkg-ubports" : {
  377. "name" : "💿 Package",
  378. "description" : "📦️ Ubuntu Touch package",
  379. "condition" : ["ubuntu"],
  380. "uri" : ["openstore:"],
  381. "web" : ["://open-store.io/app/"]
  382. },
  383. "ext-userjs" : {
  384. "name" : "🐵 Userscript", //🐒
  385. "description" : "📜 User.JS script",
  386. "extension" : [".user.js"]
  387. },
  388. "ext-usercss" : {
  389. "name" : "🎨 Userstyle",
  390. "description" : "📃 User.CSS stylesheet",
  391. "extension" : [".user.css"]
  392. },
  393. "ext-chromium" : {
  394. "name" : "🧩 Extension",
  395. "description" : "🧩 Web browser extension",
  396. "condition" : ["brave", "chrome", "chromium", "vivaldi"],
  397. "extension" : [".crx", ".chromium.zip", ".chrome.zip"],
  398. "web" : ["://chrome.google.com/webstore/detail/"]
  399. },
  400. "ext-edge" : {
  401. "name" : "🧩 Extension",
  402. "description" : "🧩 Web browser extension",
  403. "condition" : ["edge"],
  404. "web" : ["://microsoftedge.microsoft.com/addons/detail/"]
  405. },
  406. "ext-falkon" : {
  407. "name" : "🧩 Extension", // 🦅️
  408. "description" : "🧩 Web browser extension",
  409. "condition" : ["falkon"],
  410. "web" : ["://store.falkon.org/p/"]
  411. },
  412. "ext-xpi" : {
  413. "name" : "🧩 Extension", //🐺️ //🦊️ //🦎️
  414. "description" : "🧩 Web browser extension",
  415. "condition" : ["firefox", "librewolf", "waterfox"],
  416. "extension" : [".xpi", ".firefox.zip"],
  417. "web" : ["://addons.mozilla.org"]
  418. },
  419. "ext-xul" : {
  420. "name" : "🧩 Extension", // 🌕
  421. "description" : "🧩 Web browser extension",
  422. "web" : ["://addons.palemoon.org",
  423. "://realityripple.com/Software/XUL/",
  424. "://realityripple.com/Software/Mozilla-Extensions/"]
  425. },
  426. "ipfs" : {
  427. "name" : "💠 IPFS", //📁 //📂 //🗃️ //⚛️ //💎️ //🕸️
  428. "description" : "🗃️ Interplanetary File System",
  429. "uri" : ["ipfs:", "ipns:", "dweb:"],
  430. "web" : ["://gateway.pinata.cloud/ipfs/",
  431. "://ipfs.io/ipfs/",
  432. "://cloudflare-ipfs.com/ipfs/"]
  433. },
  434. "tor" : {
  435. "name" : "🧅️ Tor",
  436. "description" : "🔮 Enter the Tor system",
  437. "url" : [".onion", ".onion:"]
  438. },
  439. "i2p" : {
  440. "name" : "㊙️ i2p", //㊣
  441. "description" : "🔮 Enter the i2p system", //⚛️
  442. "url" : [".i2p", ".i2p:"]
  443. }
  444. };
  445.  
  446. const namespace = 'i2p-schimon-blackbelt';
  447.  
  448.  
  449. const objectKeys = Object.keys(types);
  450.  
  451. (function() {
  452. let links = [], accept;
  453. for (let i = 0; i < objectKeys.length; i++) {
  454.  
  455. let agent = types[objectKeys[i]].condition, accept = true;
  456. if (agent) {
  457. accept = false;
  458. for (let j = 0; j < agent.length; j++) {
  459. if (navigator.userAgent.toLowerCase().includes(agent[j])) {
  460. accept = true;
  461. }
  462. }
  463. }
  464.  
  465. //if (reject) continue;
  466.  
  467. let
  468. result,
  469. title = types[objectKeys[i]].name,
  470. descr = types[objectKeys[i]].description,
  471. array = types[objectKeys[i]];
  472.  
  473. if (array.alternate) {
  474. result = extractRel(array.alternate);
  475. }
  476.  
  477. if (!result && array.extension) {
  478. result = extractFile(array.extension);
  479. }
  480.  
  481. if (!result && array.uri) {
  482. result = extractURI(array.uri);
  483. }
  484.  
  485. if (!result && array.url) {
  486. result = extractURL(array.url);
  487. }
  488.  
  489. if (!result && array.urn) {
  490. result = extractURN(array.urn);
  491. }
  492.  
  493. if (!result && array.web) {
  494. result = extractWeb(array.web);
  495. }
  496.  
  497. if (accept && result) {
  498. links.push(createLink(result, title, descr, objectKeys[i]));
  499. }
  500. }
  501.  
  502. if (links.length) {
  503. buildBar(links);
  504. }
  505.  
  506. // https://henrik.nyh.se/
  507. // https://postmarketos.org/
  508. /* document.addEventListener ("scroll", function() {
  509. if (window.pageYOffset > 10) { // TODO when first bar is out of focus
  510. document
  511. .querySelector('#' + namespace + '-bar')
  512. .style.setProperty('position', 'fixed', 'important');
  513. } else {
  514. document
  515. .querySelector('#' + namespace + '-bar')
  516. .style.setProperty('position', 'absolute', 'important');
  517. }
  518. }) */
  519.  
  520. })();
  521.  
  522. function buildBar(links) {
  523. let barElement = document.createElement(namespace);
  524. barElement.id = namespace + '-bar';
  525. barElement.style.all = 'unset';
  526. barElement.style.width = '100%';
  527. barElement.style.opacity = 0.5; // 0.75
  528. barElement.style.backgroundColor = '#000'; //'#2c3e50';
  529. barElement.style.color = '#eee';
  530. //barElement.style.setProperty("color", "#eee", "!important")
  531. barElement.style.fontVariant = 'small-caps';
  532. barElement.style.left = 0;
  533. barElement.style.right = 0;
  534. barElement.style.top = 0;
  535. barElement.style.zIndex = 2147483647;
  536. barElement.style.maxHeight = 'fit-content';
  537. //barElement.style.maxWidth = '100vw';
  538. barElement.style.padding = '6px'; //13px //15px //11px //9px //6px //3px //1px
  539. barElement.style.position = 'fixed';
  540. barElement.style.display = 'block';
  541. barElement.style.textAlign = 'center';
  542. barElement.style.direction = 'ltr';
  543. barElement.style.userSelect = 'none';
  544. //barElement.style.overflow = 'hidden';
  545. //barElement.style.transition = 'all 1s ease 0.1s';
  546. barElement.onclick = () => { barElement.remove(); }
  547. barElement.onmouseover = () => { barElement.style.opacity = 0.9; }
  548. barElement.onmouseleave = () => {
  549. barElement.querySelector('#' + namespace + '-info-square') &&
  550. barElement.querySelector('#' + namespace + '-info-square').remove();
  551. }
  552.  
  553. barElement.onmouseout = () => {
  554. var secs = 20;
  555. function timeOut() {
  556. barElement.onmouseout = () => { secs = 20; }
  557. secs -= 1;
  558. if (secs == 15) {
  559. // FIXME Not working due to !important we have set below
  560. //barElement.style.setProperty('opacity', 'unset', 'important');
  561. barElement.style.opacity = 0.3;
  562. setTimeout(timeOut, 1000);
  563. } else if (secs == 5) {
  564. //barElement.style.setProperty('opacity', 'unset', 'important');
  565. barElement.style.opacity = 0;
  566. setTimeout(timeOut, 1000);
  567. } else if (secs == 0) {
  568. barElement.remove();
  569. return;
  570. } else {
  571. setTimeout(timeOut, 1000);
  572. }
  573. } timeOut();
  574. }
  575.  
  576. // Set !important
  577. for (let i = 0; i < barElement.style.length; i++) {
  578. barElement.style.setProperty(
  579. barElement.style[i],
  580. barElement.style.getPropertyValue(barElement.style[i]),
  581. 'important'
  582. );
  583. }
  584.  
  585. document.body.prepend(barElement);
  586.  
  587. //barElement.append(closeButton(barElement));
  588. links.forEach(link => barElement.append(link));
  589. //console.log("eles.forEach(ele => barElement.append(ele));")
  590. //console.log(eles)
  591.  
  592. if (
  593. // NOTE Not working '#i2p.schimon.blackbelt.bittorrent'
  594. barElement.querySelector('*[id$=bittorrent]') &&
  595. !barElement.querySelector('*[id$=-torrent]')
  596. ) {
  597. // TODO Add after BitTorrent
  598. // TODO place this in the tooltip
  599. barElement.prepend(createLink(
  600. generateTorrent(barElement),
  601. '🎁️ Torrent',
  602. '⛲️ BitTorrent metadata file',
  603. 'torrent'))
  604. }
  605.  
  606. // Timer from https://stackoverflow.com/questions/27406765/hide-div-after-x-amount-of-seconds
  607.  
  608. var secs = 33;
  609. function timeOut() {
  610. secs -= 1;
  611. if (secs == 0) {
  612. //barElement.style.display = 'none';
  613. barElement.style.opacity = 0.2;
  614. return;
  615. }
  616. else {
  617. setTimeout(timeOut, 1000);
  618. }
  619. }
  620. timeOut();
  621.  
  622. }
  623.  
  624.  
  625.  
  626. function infoBox(node) {
  627. node.addEventListener ("mouseover", function() {
  628. if (this.title) {
  629. this.setAttribute('info', this.title);
  630. this.removeAttribute('title');
  631. }
  632. if (document.querySelector('#' + namespace + '-info-square')) {
  633. document.querySelector('#' + namespace + '-info-square').remove();
  634. }
  635. let infoSquare = document.createElement('info-square');
  636. infoSquare.id = namespace + '-info-square';
  637. infoSquare.innerHTML = this.getAttribute('info');
  638. infoSquare.style.all = 'unset';
  639. infoSquare.style.fontVariant = 'none';
  640. infoSquare.style.position = 'fixed';
  641. infoSquare.style.margin = 'auto';
  642. //infoSquare.style.top = '15%';
  643. infoSquare.style.right = '25%';
  644. infoSquare.style.left = '25%';
  645. infoSquare.style.padding = '10px';
  646. infoSquare.style.color = '#000';
  647. infoSquare.style.background = 'WhiteSmoke';
  648. infoSquare.style.borderRadius = '5px';
  649. infoSquare.style.border = '3px solid #000';
  650. /*
  651. infoSquare.style.width = 50%;
  652. infoSquare.style.font-size = 70%;
  653. */
  654. infoSquare.style.fontFamily = 'system-ui';
  655. //infoSquare.style.justifyContent = 'center';
  656. //infoSquare.style.alignItems = 'center';
  657. infoSquare.style.textAlign = 'center';
  658. infoSquare.style.display = 'block';
  659. /* white-space = pre; in case we have html tags */
  660. //infoSquare.textContent = text;
  661. infoSquare.style.zIndex = 2147483647;
  662. document.querySelector('#' + namespace + '-bar').append(infoSquare);
  663. });
  664. }
  665.  
  666. // NOTE TODO semi-recursive callback
  667. // NOTE TODO typeof
  668. function extractFile(array) {
  669. let i = 0;
  670.  
  671. do {
  672. // FIXME Mainstream to support ends-with
  673. // fn:ends-with appears to be missing in some engines
  674. query = [
  675. '//a[contains(@href, "' + array[i] + '")]/@href',
  676. '//a[contains(@download, "' + array[i] + '")]/@download'];
  677. // '//a[ends-with(@href, "' + array[i] + '")]/@href'
  678. // '//a[ends-with(text(), "' + array[i] + '")]/@href'
  679. result = executeQuery(query, 'xpath');
  680. i = i + 1;
  681. } while (!result && i < array.length);
  682.  
  683. if (result) {
  684. protocol = location.protocol
  685. hostname = location.hostname
  686. //console.log(result)
  687. switch (true) {
  688.  
  689. case (result.startsWith('/')):
  690. result = protocol + '//' + hostname + result;
  691. break;
  692.  
  693. case (!result.includes(':')):
  694. result = protocol + '//' + hostname + '/' + result;
  695. break;
  696.  
  697. //case (result.startsWith('http')):
  698. //break;
  699. }
  700.  
  701. //console.log(result)
  702. let url = new URL(result);
  703. let bol = url.pathname.endsWith(array[i-1]);
  704. if (bol) { return result; };
  705. }
  706. }
  707.  
  708.  
  709. function extractRel(array) {
  710. let i = 0;
  711.  
  712. do {
  713. query = [
  714. // Also rel="feed". See https://miranda-ng.org/
  715. '//link[@rel="alternate"\
  716. and contains(@type, "' + array[i] + '")\
  717. ]/@href'];
  718. result = executeQuery(query, 'xpath');
  719. i = i + 1;
  720. } while (!result && i < array.length);
  721.  
  722. if (result) { return result; };
  723. }
  724.  
  725.  
  726. function extractURI(array) {
  727. let i = 0;
  728.  
  729. do {
  730. query = [
  731. '//a[starts-with(@href, "' + array[i] + '")\
  732. and not(starts-with(@href, "tg://msg_url?"))\
  733. and not(starts-with(@href, "mailto:?"))\
  734. and not(contains(@href, "/send?"))\
  735. ]/@href'];
  736. result = executeQuery(query, 'xpath');
  737. i = i + 1;
  738. } while (!result && i < array.length);
  739.  
  740. if (result) {
  741. let url = new URL(result);
  742. let bol = url.protocol.match(array[i-1]);
  743. if (bol) { return result; };
  744. }
  745. }
  746.  
  747.  
  748. function extractURL(array) {
  749. let i = 0;
  750.  
  751. do {
  752. query = [
  753. '//a[starts-with(@href, "http")\
  754. and contains(@href, "' + array[i] + '")\
  755. ]/@href'];
  756. // FIXME mainstream
  757. //'//a[starts-with(@href, "http") and ends-with(@href, "' + array[i] + '")]/@href'
  758. result = executeQuery(query, 'xpath');
  759. i = i + 1;
  760. } while (!result && i < array.length);
  761.  
  762. if (result) {
  763. let url = new URL(result);
  764. let bol = url.hostname.endsWith(array[i-1]);
  765. if (bol) { return result };
  766. //if (!url) {
  767. // url = url.host.contains(array[i] + ':');
  768. //}
  769. }
  770. }
  771.  
  772.  
  773. function extractURN(array) {
  774. let i = 0;
  775.  
  776. do {
  777. query = [
  778. '//a[starts-with(@href, "magnet")\
  779. and contains(@href, "' + array[i] + '")\
  780. ]/@href'];
  781. result = executeQuery(query, 'xpath');
  782. i = i + 1;
  783. } while (!result && i < array.length);
  784.  
  785. if (result) {
  786. let url = new URL(result);
  787. url.searchParams.delete('tr');
  788. result = url.protocol + url.search;
  789. result = decodeURIComponent(result);
  790. return result;
  791. //let bol = url.hostname.startsWith(array[i-1]);
  792. //if (bol) { createLink(result, type) };
  793. }
  794. }
  795.  
  796.  
  797. function extractWeb(array) {
  798. let i = 0;
  799.  
  800. do {
  801. query = [
  802. '//a[starts-with(@href, "http")\
  803. and contains(@href, "' + array[i] + '")\
  804. and not(starts-with(@href, "https://wa.me/?text"))\
  805. and not(starts-with(@href, "https://t.me/share"))\
  806. and not(starts-with(@href, "https://telegram.me/share"))\
  807. and not(contains(@href, "com.github.android"))\
  808. and not(contains(@href, "1477376905"))\
  809. ]/@href'];
  810. result = executeQuery(query, 'xpath');
  811. i = i + 1;
  812. } while (!result && i < array.length);
  813.  
  814. if (result) { return result; };
  815. }
  816.  
  817.  
  818. // TODO
  819. // String.prototype.toLowerCase()
  820. // href Magnet: (magnet:) is not detected, or
  821. // Set document MIMEType to plain/text
  822. function executeQuery(queries, method) {
  823.  
  824. let i = 0;
  825. do {
  826. switch(method) {
  827. case 'css':
  828. result = document.querySelector(queries[i]);
  829. //if (result) {result = result.href};
  830. if (result) {return result.href};
  831. break;
  832.  
  833. case 'xpath':
  834. // NOTE This may cause 404 error.
  835. // Use getPathTo()
  836. // https://stackoverflow.com/questions/2631820/how-do-i-ensure-saved-click-coordinates-can-be-reload-to-the-same-place-even-if/2631931#2631931
  837. /*
  838. xhtmlFile = new XMLSerializer().serializeToString(document).toLowerCase()
  839. //xhtmlFile = '<html>'+document.documentElement.innerHTML.toLowerCase()+'</html>'
  840. domParser = new DOMParser();
  841. xhtmlFile = domParser.parseFromString(xhtmlFile, 'text/html');
  842. result = document.evaluate(
  843. queries[i], xhtmlFile, null, XPathResult.STRING_TYPE);
  844. */
  845. result = document.evaluate(
  846. queries[i], document, null, XPathResult.STRING_TYPE);
  847. //if (result) {result = result.stringValue};
  848. if (result) {return result.stringValue};
  849. }
  850. } while (!result && i < queries.length);
  851. }
  852.  
  853. function createLink(uri, title, info, id) {
  854. //if (type[4]) {
  855. //let tip = document.createElement('spna');
  856. //tip.class = 'tooltip';
  857. //tip.append('type[4]');
  858. //}
  859.  
  860. //type = type.split(' ');
  861. //sym = getUrnProperty(uri, 'sym');
  862. //net = getUrnProperty(uri, 'net');
  863.  
  864. let aElement = document.createElement('a');
  865. aElement.id = namespace + '-' + id;
  866. aElement.textContent = title;
  867. aElement.href = uri;
  868. aElement.title = info;
  869. aElement.style.all = 'unset';
  870. aElement.style.color = '#eee';
  871. aElement.style.font = 'caption';
  872. aElement.style.fontFamily = 'system-ui';
  873. aElement.style.fontSize = '15px'; // 13px
  874. aElement.style.fontVariantCaps = 'all-small-caps';
  875. aElement.style.textDecoration = 'none';
  876. aElement.style.cursor = 'default';
  877.  
  878. //aElement.style.fontWeight = 'bold';
  879. //aElement.style.padding = '3px 9px 3px 9px';
  880. //aElement.style.margin = '0 9px 0 9px';
  881. aElement.style.margin = '2% 9px 2% 9px';
  882. //aElement.style.background = 'black';
  883. //aElement.style.borderBottomLeftRadius = '9px';
  884. //aElement.style.borderBottomRightRadius = '9px';
  885.  
  886. //aElement.style.forEach (style => style + '!important');
  887. for (let i = 0; i < aElement.style.length; i++) {
  888. aElement.style.setProperty(
  889. aElement.style[i],
  890. aElement.style.getPropertyValue(aElement.style[i]),
  891. 'important'
  892. );
  893. }
  894.  
  895. infoBox(aElement);
  896.  
  897. //aElement.append(tip);
  898.  
  899. //console.log(aElement)
  900. //console.log(aElements)
  901. return aElement;
  902. }
  903.  
  904. // Torrent V1
  905. // TODO handle compressed sha1 http://www.debath.co.uk/MakeAKey.html
  906. // TODO convert base32 to hash
  907. // 32/40 https://linuxtracker.org/?page=torrent-details&id=173a0f61ef92b158547937fa0c01e9dc704779f9
  908. function generateTorrent(node) {
  909. // TODO generate link else-if onclick
  910. // 404 https://bookshelf.theanarchistlibrary.org/library/librarian-previous-announcements-en#toc1
  911. href = node.querySelector('*[id*=bittorrent]').href;
  912. let url = new URL(href);
  913. name = url.searchParams.get('dn');
  914. if (!name) {name = document.title};
  915. //xt = url.searchParams.get('xt');
  916. hash = url.searchParams.get('xt').slice(9);
  917. //if (ha.length === 40 && xt.startsWith('urn:btih'))
  918. if (hash.length === 40) {
  919. links = [
  920. 'https://watercache.libertycorp.org/get/' + hash + '/' + name,
  921. 'https://itorrents.org/torrent/' + hash + '.torrent?title=' + name,
  922. 'https://firecache.libertycorp.org/get/' + hash + '/' + name,
  923. 'http://fcache63sakpihd44kxdduy6kgpdhgejgp323wci435zwy6kiylcnfad.onion/get/' + hash + '/' + name,
  924. ];
  925. return links[1];
  926. }
  927. }
  928.  
  929. function closeButton(barElement) {
  930.  
  931.  
  932. let spanElement = document.createElement('span');
  933. spanElement.textContent = 'X';
  934. spanElement.style.all = 'unset';
  935. spanElement.style.color = '#eee';
  936. spanElement.style.font = 'caption';
  937. spanElement.style.fontFamily = 'system-ui';
  938. spanElement.style.fontSize = '15px'; // 13px
  939. spanElement.style.fontVariantCaps = 'all-small-caps';
  940. spanElement.style.textDecoration = 'none';
  941.  
  942. spanElement.style.fontWeight = 'bold';
  943. spanElement.style.padding = '3px 9px 3px 9px';
  944. //spanElement.style.margin = '0 9px 0 9px';
  945. spanElement.style.background = 'black';
  946. spanElement.style.borderBottomLeftRadius = '9px';
  947. spanElement.style.borderBottomRightRadius = '9px';
  948.  
  949. //spanElement.style.forEach (style => style + '!important');
  950. for (let i = 0; i < spanElement.style.length; i++) {
  951. spanElement.style.setProperty(
  952. spanElement.style[i],
  953. spanElement.style.getPropertyValue(spanElement.style[i]),
  954. 'important'
  955. );
  956. }
  957.  
  958. spanElement.onclick = () => { barElement.remove(); }
  959.  
  960. return spanElement;
  961.  
  962. }