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

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