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-06-01 提交的版本,查看 最新版本

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