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