This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildQueryStr(obj) { | |
| const s = new URLSearchParams(); | |
| Object.keys(obj).forEach((key) => { | |
| s.set(key, obj[key]); | |
| }); | |
| return s.toString(); | |
| } | |
| const randomBetween = (min, max) => { | |
| return Math.round(Math.random() * (max - min)) + min; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function connectToWindow(listener) { | |
| const port = await new Promise((resolve) => { | |
| const handleMessage = (e) => { | |
| if (e.data.type === "__messaging_connect__") { | |
| resolve(e.ports[0]); | |
| self.removeEventListener("message", handleMessage); | |
| } | |
| }; | |
| self.addEventListener("message", handleMessage); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getCacheAll = async (name, q) => { | |
| const cache = await caches.open(name); | |
| return cache.matchAll(q); | |
| }; | |
| const logText = (matches) => | |
| Promise.all(matches.map((r) => r.text().then((txt) => [r.url, txt]))); | |
| async function clearCache(name) { | |
| const cache = await caches.open(name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const select = (obj, propArr) => | |
| propArr.reduce((acc, val) => { | |
| acc[val] = obj[val]; | |
| return acc; | |
| }, {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function scrollToBottom() { | |
| const scrollingElement = document.scrollingElement || document.body; | |
| scrollingElement.scrollTop = scrollingElement.scrollHeight; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fetch = (...args) => | |
| import("node-fetch").then(({ default: fetch }) => fetch(...args)); | |
| const { buildQueryStr, timeTaken } = require("./helpers.js"); | |
| async function getSource({ q, ...params } = {}, page = 1) { | |
| if (!q) throw Error("{ q } is a manadatory parameter!"); | |
| const url = | |
| `https://www.google.com/search?` + | |
| buildQueryStr({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const functionalize = (arr) => { | |
| const result = {}; | |
| for (let funcOrArr of arr) { | |
| const [func, indexOfData = 0] = | |
| funcOrArr.constructor.name === "Array" ? funcOrArr : [funcOrArr]; | |
| const name = func.name || func; | |
| result[name] = | |
| (...args) => | |
| (data) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const parseToDOM = Range.prototype.createContextualFragment.bind( | |
| document.createRange() | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function css(obj) { | |
| return Object.keys(obj) | |
| .map((key) => { | |
| const newKey = key.replace( | |
| /[A-Z]/, | |
| (match, index) => "-" + match.toLowerCase() | |
| ); | |
| return `${newKey}:${obj[key]};`; | |
| }) | |
| .join("\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function fetchLink(q) { | |
| const htmlStr = await fetch( | |
| 'https://duckduckgo.com/?q=' + q + '&ia=web' | |
| ).then((r) => r.text()) | |
| return `https://links.duckduckgo.com/${htmlStr.match(/\/(d.js.+?)&p_ent/)[1]}` | |
| } | |
| async function fetchDuck(q) { | |
| function transform({ u, t, a, i }) { | |
| return { |