You are an expert at JavaScript and C#
. You must format indents using 2 spaces, and you must wrap strings using doublequotes " instead of '.
Let's think step by step.
// OpenAIPlaygroundShowPresets.js -- Bookmarklet to fix March 2024 CSS regressive bug (~"GM_addStyle" but without TamperMonkey or GreaseMonkey) | |
// by Darren Semotiuk, see: https://community.openai.com/t/playground-recent-ui-changes-broke-mobile-experience/687130 | |
// BOOKMARKLET* for those of us not running TamperMonkey or GreaseMonkey | |
// *Simply add the one-liner below as a Favorite/Bookmark in your browser, no extensions required! | |
javascript:void function(){globalThis.GM_addStyle=globalThis.GM_addStyle||function(a){let b=document,c=b.head||b.body,d=b.createElement("style");d.type="text/css",d.innerText=a,c&&c.appendChild(d)},GM_addStyle("@media(max-width:500px){.pg-header-actions,.pg-header-section-settings,.pg-preset-select-container{display:block !important}}")}(); |
// replaced.js ( v: any, ...rules: Array of [pattern: any, replaceWith: string | function, optionalRegExpFlags: string | null | undefined] ) | |
const replaced = (v, ...rules) => { | |
return rules.reduce( (acc, rule) => ( | |
acc.replace( | |
RegExp( rule[0], rule[2] == null ? "g" : rule[2] ), | |
rule[1] | |
) | |
), String( v ?? "" ) ); | |
}; |
I want to write a Chrome extension. I need the most minimal code for the V3 manifest and worker.js to trigger a download prompt of a data url generated by btoa() of the capture as mhtml function. Use only async await and arrow functions instead of promises and callbacks wherever possible. Use blob.text() instead of FileReader. Image128 .png and no popups or content scripts.
(02Feb2024 806am)
To create a minimal Chrome extension that triggers a download prompt of a captured page in MHTML format using Manifest V3, you need to include the following files in your extension:
manifest.json
: The metadata file, which includes information about the extension like its name, version, permissions, and which script to run as the service worker.// range(arraySize, optionalMapFunction, optionalEachFunction).js | |
// https://gist.github.com/DarrenSem/bc0403bcdad09912eb298e6d3b4824fe | |
const range = ( arraySize, fnMapIndex, fnEachIndexFirst, _indexes ) => ( | |
_indexes = Array.from( Array(arraySize | 0).keys() ), // because [...Array(arraySize | 0).keys()] triggers TypeScript/VSC error: Type 'IterableIterator' is not an array type or a string type. | |
fnEachIndexFirst && _indexes.forEach( index => fnEachIndexFirst(index) ), | |
fnMapIndex && ( _indexes = _indexes.map( index => fnMapIndex(index) ) ), | |
_indexes | |
); |
// FizzBuzz expanded - wordmod.js - because why not | |
// https://gist.github.com/DarrenSem/3a63b31542487bb1fd38e08976d8d215 | |
let wordmod = ( limit = 100, words = { 3: "Fizz", 5: "Buzz" }, sep = "\n" ) => { | |
let results = []; | |
for (let i = 1; i <= limit; i ++) { | |
let result = ""; | |
for ( let [divisor, word] of Object.entries(words) ) { |
// MongoDB - function getDocumentArray( fnEachDocument, ...documents ) - returns cloned Array of passed documents (after running function on each) | |
// Purpose: returns cloned Array of passed documents (after running function on each) | |
// Usage: const docArray = getDocumentArray( fnEachDocument, ...documents ); await coll.insertMany(docArray); | |
// see the docs for https://www.mongodb.com/docs/manual/reference/method/db.collection.insertMany | |
// esp. "_id Field" https://www.mongodb.com/docs/manual/reference/method/db.collection.insertMany/#_id-field | |
// ^ because DURING THE .insert[Many|One]() call, "_id" field is ADDED to the original document! (if missing) | |
const getDocumentArray = ( fnEachDocument, ...documents ) => ( | |
fnEachDocument ||= ( document => document ), |
// ytSubs.js (SEE DISCLAIMER) - via @DarrenSem https://gist.github.com/DarrenSem (22Mar2024) | |
// YouTube subtitles - English (auto-generated) CC (closed captions) | |
// Usage: node ytSubs.js videoIdOrUrl | |
// or Web browser BOOKMARKLET (contents open in a new window) | |
// ES6 clickable Bookmarklet = 3923 chars: | |
//javascript:void function(){"use strict";var e=String.fromCharCode;const n=!1,d=globalThis,{process:i}=d,t=console,u=async(e,n,d="text")=>fetch(e,n).then(e=>e[d]()),a=e=>{try{e=(e||"")+"";const n=e.match(/"captionTracks":.*"isTranslatable"\:.*?}]/),d=JSON.parse(`{${(n||[""])[0]}}`).captionTracks||[],i=d.map(e=>{const n=e.name;return[l(n.simpleText||n.runs&&n.runs[0].text),e.baseUrl+"&fmt=json3"]});return i}catch(n){}},r=e=>{e=new Date(e);let n=e.getDate();return isNaN(n)?null:`${(n+"").padStart(2,"0")}${e.toLocaleString("default",{month:"short"})}${e.getFullYear()}`},f=e=>{e="string"!=typeof e&&e?new URL(e):{href:e||""};const n=e&&e.href.trim()||"",d=n.replace(/(https?:\/\/)?\/*(.+?)\/?$/,"https://$2"),i=d |
// hostnameRoot.js -- returns URL/location.hostname with certain prefixes removed: m. mob. mobi. mobile. www. www[0-9]. ww[0-9]. | |
const hostnameRoot = hostname => String(hostname ?? "") | |
.toLowerCase() | |
.replace( | |
/^(m(ob(i(le)?)?)?|ww(w?\d|w))\.(.+?\..+)/, | |
"$6" | |
); | |
console.log([ |
Minimal polyfill (324 characters minified) for client-side JS to add missing NodeJS functions for completing HackerRank.com challenges -- process.stdin/stdout/env.OUTPUT_PATH and require("fs").createWriteStream
(So I can complete HackerRank.com challenges on my cell using my custom REPL bookmarklet.)