Skip to content

Instantly share code, notes, and snippets.

@SnarkyDeveloper
Last active January 4, 2026 00:08
Show Gist options
  • Select an option

  • Save SnarkyDeveloper/79c20d50f4b0435f095d531f90b60b02 to your computer and use it in GitHub Desktop.

Select an option

Save SnarkyDeveloper/79c20d50f4b0435f095d531f90b60b02 to your computer and use it in GitHub Desktop.
Inline Helper - Browser JS/Bookmarklet
(function() {
"use strict";
let messages = [];
const baseUrl = 'https://text.pollinations.ai/';
const system =
'You are a simple browser agent model that returns short answers to the user, consise and simple. Selections by user in browser will be indicated by SELECTION[text], where text is what is currently selected. You will not bring up specific things like SELECTION[text]';
function toMessage(role, content, image_blob=undefined) {
if (image_blob) {
let r = { role: role, content: [{type: "text", text: content}] };
r.content.push({
type: "image_url",
image_url: {
url: `data:image/jpeg;base64,${image_blob}`
}
});
return r;
}
return { role: role, content: content };
}
function truncate(str) {
if (str.length <= 150) {
return str;
} else {
return str.slice(0, 147) + '...';
}
}
async function ask() {
let m = '';
messages.forEach(msg => {
let c = msg.content.replace(/SELECTION\[.*?\\\]/g, "");
m += `${(str => str.charAt(0).toUpperCase() + str.slice(1))(msg.role)}: ${truncate(c)}\n`;
});
m += '========================\nWhat would you like to ask?\n(#[page] to attach page screenshot)';
if (m.length > 1000) {
m.slice(-1000); // ret last 1000 characters
}
let question = prompt(m);
if (question === null || question === "") {
return;
}
if (window.getSelection().toString() !== '') {
question += `SELECTION[${window.getSelection().toString().trimEnd()}\\]`;
}
let img;
if (question.includes('#[page]')) {
if (window.html2canvas === undefined) {
const r = await fetch("https://cdn.jsdelivr.net/npm/html2canvas-pro@1.5.13/dist/html2canvas-pro.min.js").catch(e => { throw new Error(`Error occurred While Fetching html2canvas-pro, check cors? ${e}`) });
const code = await r.text();
eval(code);
}
const canvas = await html2canvas(document.body, {
x: window.scrollX,
y: window.scrollY,
width: window.innerWidth,
height: window.innerHeight,
scale: 0.5, // COMPRESSIONNNN 🤑
backgroundColor: "#fff",
useCORS: true,
logging: false
}).catch(e => { throw new Error(`Error occurred while taking a screenshot: ${e}`) })
img = canvas.toDataURL("image/jpeg", 0.45).split(",")[1];
}
const payload = {
model: 'openai',
messages: [{ role: 'system', content: system }, toMessage("user", question, img)].concat(messages),
max_tokens: 350,
stream: false,
};
fetch(baseUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
.then(r => {
if (!r.ok) {
throw new Error(`Error: ${r.stausText}, Code: ${r.statusCode})`);
}
let text = r.text();
messages.push(toMessage("user", question));
text.then(s => {
messages.push(toMessage("assistant", s))
alert(`Assistant:\n${s}`)
})
})
.catch(e => {
throw new Error(`Error occurred while trying to ask pollinations: ${e}`)
});
}
function handleAltAKeyPress(event) {
const isAltPressed = event.altKey;
const isAPressed = event.key === 'a' || event.key === 'A';
if (isAltPressed && isAPressed) {
event.preventDefault();
ask().catch(e => { console.error(e); alert(`An Error Occured! \nTrace: ${e}`); });
}
}
document.addEventListener('keydown', handleAltAKeyPress);
})();
!function(){"use strict";let messages=[],baseUrl="https://text.pollinations.ai/",system="You are a simple browser agent model that returns short answers to the user, consise and simple. Selections by user in browser will be indicated by SELECTION[text], where text is what is currently selected. You will not bring up specific things like SELECTION[text]";function toMessage(t,e,n){if(n){let r={role:t,content:[{type:"text",text:e}]};return r.content.push({type:"image_url",image_url:{url:`data:image/jpeg;base64,${n}`}}),r}return{role:t,content:e}}function truncate(t){return t.length<=150?t:t.slice(0,147)+"..."}async function ask(){let m="";messages.forEach(t=>{var e;m+=`${(e=t.role).charAt(0).toUpperCase()+e.slice(1)}: ${truncate(t.content.replace(/SELECTION\[.*?\\\]/g,""))}`}),(m+="========================\nWhat would you like to ask?\n(#[page] to attach page screenshot)").length>1e3&&m.slice(-1e3);let question=prompt(m);if(null===question||""===question)return;""!==window.getSelection().toString()&&(question+=%60SELECTION[${window.getSelection().toString().trimEnd()}\\]%60);let img;if(question.includes("#[page]")){if(void 0===window.html2canvas){let r=await fetch("https://cdn.jsdelivr.net/npm/html2canvas-pro@1.5.13/dist/html2canvas-pro.min.js").catch(t=>{throw Error(%60Error occurred While Fetching html2canvas-pro, check cors? ${t}%60)}),code=await r.text();eval(code)}let canvas=await html2canvas(document.body,{x:window.scrollX,y:window.scrollY,width:window.innerWidth,height:window.innerHeight,scale:.5,backgroundColor:"#fff",useCORS:!0,logging:!1}).catch(t=>{throw Error(%60Error occurred while taking a screenshot: ${t}%60)});img=canvas.toDataURL("image/jpeg",.45).split(",")[1]}let payload={model:"openai",messages:[{role:"system",content:system},toMessage("user",question,img)].concat(messages),max_tokens:350,stream:!1};fetch(baseUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)}).then(t=>{if(!t.ok)throw Error(%60Error: ${t.stausText}, Code: ${t.statusCode})%60);let e=t.text();messages.push(toMessage("user",question)),e.then(t=>{messages.push(toMessage("assistant",t)),alert(%60Assistant:${t}%60)})}).catch(t=>{throw Error(%60Error occurred while trying to ask pollinations: ${t}%60)})}function handleAltAKeyPress(t){let e=t.altKey,n="a"===t.key||"A"===t.key;e&&n&&(t.preventDefault(),ask().catch(t=>{console.error(t),alert(%60An Error Occured! Trace: ${t}%60)}))}document.addEventListener("keydown",handleAltAKeyPress)}();

How to install

  1. Create a new bookmark
  2. Copy contents of helper.min.js or copy from here:
!function(){"use strict";let messages=[],baseUrl="https://text.pollinations.ai/",system="You are a simple browser agent model that returns short answers to the user, consise and simple. Selections by user in browser will be indicated by SELECTION[text], where text is what is currently selected. You will not bring up specific things like SELECTION[text]";function toMessage(t,e,n){if(n){let r={role:t,content:[{type:"text",text:e}]};return r.content.push({type:"image_url",image_url:{url:`data:image/jpeg;base64,${n}`}}),r}return{role:t,content:e}}function truncate(t){return t.length<=150?t:t.slice(0,147)+"..."}async function ask(){let m="";messages.forEach(t=>{var e;m+=`${(e=t.role).charAt(0).toUpperCase()+e.slice(1)}: ${truncate(t.content.replace(/SELECTION\[.*?\\\]/g,""))}`}),(m+="========================\nWhat would you like to ask?\n(#[page] to attach page screenshot)").length>1e3&&m.slice(-1e3);let question=prompt(m);if(null===question||""===question)return;""!==window.getSelection().toString()&&(question+=%60SELECTION[${window.getSelection().toString().trimEnd()}\\]%60);let img;if(question.includes("#[page]")){if(void 0===window.html2canvas){let r=await fetch("https://cdn.jsdelivr.net/npm/html2canvas-pro@1.5.13/dist/html2canvas-pro.min.js").catch(t=>{throw Error(%60Error occurred While Fetching html2canvas-pro, check cors? ${t}%60)}),code=await r.text();eval(code)}let canvas=await html2canvas(document.body,{x:window.scrollX,y:window.scrollY,width:window.innerWidth,height:window.innerHeight,scale:.5,backgroundColor:"#fff",useCORS:!0,logging:!1}).catch(t=>{throw Error(%60Error occurred while taking a screenshot: ${t}%60)});img=canvas.toDataURL("image/jpeg",.45).split(",")[1]}let payload={model:"openai",messages:[{role:"system",content:system},toMessage("user",question,img)].concat(messages),max_tokens:350,stream:!1};fetch(baseUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)}).then(t=>{if(!t.ok)throw Error(%60Error: ${t.stausText}, Code: ${t.statusCode})%60);let e=t.text();messages.push(toMessage("user",question)),e.then(t=>{messages.push(toMessage("assistant",t)),alert(%60Assistant:${t}%60)})}).catch(t=>{throw Error(%60Error occurred while trying to ask pollinations: ${t}%60)})}function handleAltAKeyPress(t){let e=t.altKey,n="a"===t.key||"A"===t.key;e&&n&&(t.preventDefault(),ask().catch(t=>{console.error(t),alert(%60An Error Occured! Trace: ${t}%60)}))}document.addEventListener("keydown",handleAltAKeyPress)}();
  1. Right click bookmark and click edit
  2. Type "javascript:"
  3. Paste script
  4. Enjoy!

How to use

  • Opening menu - Alt + A
  • Resetting Memory - Reload Page (Ctrl + R)
  • Hide Menu - Esc
  • Submit Question - Enter

Errors

  1. Click F12, or Ctrl+Shift+I
  2. On the right side check for VM:
  3. Read Error Diagnostic

TODO:

  • Agent mode (Clicking Reading InnerHTML) - Hard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment