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.

当前为 2024-03-19 提交的版本,查看 最新版本

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