Black Belt

Finds useful links and displays a top bar with various of links from contact details to media documents, including Metalinks, Podcasts, Syndication Feeds (Atom, JSON & RSS), Torrents and Userscripts. Also supports Chat, Email, Geoposition, IPFS, Magnet links of eXact Topic (xt), VoIP, Wallet schemes and more.

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

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