Skip to content

Instantly share code, notes, and snippets.

@chrisns
Last active October 9, 2024 10:00
Show Gist options
  • Save chrisns/560c7e3ad0b9806a4f03b8fec3ef4293 to your computer and use it in GitHub Desktop.
Save chrisns/560c7e3ad0b9806a4f03b8fec3ef4293 to your computer and use it in GitHub Desktop.
cns.me DE-BS BOT 3000 πŸ€–πŸ€ͺ UserScript
// ==UserScript==
// @name cns.me DE-BS BOT 3000 πŸ€–πŸ€ͺ
// @namespace http://tampermonkey.net/
// @version 2024-09-18
// @description Remove BS from register articles
// @author Chris Nesbitt-Smith
// @match https://www.theregister.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=theregister.com
// @connect 127.0.0.1
// ==/UserScript==
async function foo(title, body, summaryElement, marked, ollama) {
const messages = [
{role: "user",
content: `You are a very adept pessimistic and cynical technical specailist who is fantastic at reading a news article, cutting out the BS and hype, don't just summarise it, pick out the underlying things at play.
Be very pessimistic and cynical, call out what is clear innovation and news.
Call out the vendor that has likely seeded the article.
You will be provided a title and article body, you must respond with markdown and format your response as follows:
example for format ONLY!
## Hyperbole:
- bullet 1
- bullet 2
## Vendors:
- bullet 1
- bullet 2
## People:
- bullet 1
- bullet 2
## Actual Legimate News:
- bullet 1
- bullet 2
`
},
{role: "user",
content: JSON.stringify({"title": title, "body": body})
}
]
var content = "";
ollama.chat(messages, (error, response) => {
if (error) {
console.error(error);
} else {
content += response.message.content
summaryElement.innerHTML = marked.parse(`# cns.me DE-BS-BOT-3000 πŸ€–πŸ€ͺ Summary:\n` + content);
}
});
}
(async function() {
'use strict';
const { marked } = await import("https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js");
const Ollama = await import("https://cdn.jsdelivr.net/npm/ollama-js-client/dist/browser/index.js")
const ollama = new Ollama.default({
model: "llama3.2",
url: "http://127.0.0.1:11434/api/",
options: {
temperature: 0.4,
num_ctx: 128000
},
})
let summaryElement = document.createElement('div');
summaryElement.style.border = '3px solid black';
summaryElement.style.backgroundColor = 'light-grey';
summaryElement.style.padding = '1em';
summaryElement.style.marginBottom = '1em';
summaryElement.style.fontSize = "1.2em";
summaryElement.innerHTML = marked.parse(`# The cns.me DE-BS-BOT-3000 is Thinking...<br/> πŸ€– πŸ€”`);
let bodyDiv = document.getElementById('body')
foo(document.title, bodyDiv.textContent, summaryElement, marked, ollama)
bodyDiv.parentNode.insertBefore(summaryElement, bodyDiv);
})();
// ==UserScript==
// @name cns.me Legit BOT 3001 πŸ€–πŸ€ͺ
// @namespace http://tampermonkey.net/
// @version 2024-09-18
// @description is it legit
// @author Chris Nesbitt-Smith
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=theregister.com
// @require https://code.jquery.com/jquery-3.6.0.slim.min.js
// @connect 127.0.0.1
// @grant GM_addStyle
// ==/UserScript==
async function foo(summaryElement, marked, ollama) {
const messages = [
{role: "user",
content: `You are a very adept pessimistic and cynical technical specailist who is fantastic at reading news articles, social media posts, emails, whatsapp messages, cutting out the BS and hype, don't just summarise it, pick out the underlying things at play.
Be very pessimistic and cynical, call out what is legimimate news, be very cautious over advising the user to proceed with any associated calls to action.
Your recomendations should be formed relation to pragmatic actions someone should take based on this information, you should not suggest additional fact checking thats why they're asking you.
You will be provided a text selection and url that it came from, you must respond with markdown and format your response as follows:
example for format ONLY!
## Hyperbole:
- bullet 1
- bullet 2
## Reasons NOT to trust this:
- bullet 1
- bullet 2
## Reasons to trust this:
- bullet 1
- bullet 2
## Conclusion: should you trust this and why?
A paragraph highlighting a recommendation in bold
- βœ… Make small financial payment
- ❌ Make substantial financial payment
- ❌ Share this with others
- ❌ Make personal health decisions
`
},
{role: "user",
content: JSON.stringify({"title": document.title, "url": window.location.href, "body": getSelectionText()})
}
]
var content = "";
ollama.chat(messages, (error, response) => {
if (error) {
console.error(error);
} else {
content += response.message.content
summaryElement.innerHTML = marked.parse(`# cns.me DE-BS-BOT-3001 πŸ€–πŸ€ͺ Summary:\n` + content);
}
});
}
function getSelectionText() {
let text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
if (text === "") {
text = document.getElementsByTagName('main')[0].textContent
}
return text;
}
(async function() {
'use strict';
const { marked } = await import("https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js");
const Ollama = await import("https://cdn.jsdelivr.net/npm/ollama-js-client/dist/browser/index.js")
const ollama = new Ollama.default({
model: "llama3.2",
url: "http://127.0.0.1:11434/api/",
options: {
temperature: 0.4,
num_ctx: 128000
},
})
let summaryElement = document.createElement('div');
summaryElement.id = "cnsbot"
const css = `
#cnsbot {
border: 3px solid black;
background-color: lightgrey;
padding: 1em;
margin-bottom:1em;
font-size: 1.2em;
}
#cnsbot strong {
display:inline;
font-weight: bold;
}
#cnsbot * {
all: initial;
display:block;
font-family:Helvetica;
}
#cnsbot h1 {
font-size:2em;
}
#cnsbot h2 {
font-size:1.5em;
}
#cnsbot ul {
list-style-type: disc;
margin-left: 20px;
padding-left: 20px;
}
#cnsbot li {
display: list-item;
}`
GM_addStyle(css)
summaryElement.innerHTML = marked.parse(`# The cns.me DE-BS-BOT-3001 is Thinking...<br/> πŸ€– πŸ€”`);
let bodyDiv = document.getElementsByTagName('body')[0]
$("body").keypress(e => {
if(e.key ==="a" & e.ctrlKey) {
foo(summaryElement, marked, ollama)
bodyDiv.insertBefore(summaryElement, bodyDiv.firstChild);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment