Added INCH code to repo

Signed-off-by: Jacob <jacob@torrey.io>
pull/6/head
Jacob 2023-06-05 15:27:34 -06:00 zatwierdzone przez Jacob Torrey
rodzic 1f64b957f4
commit 68a7aba621
5 zmienionych plików z 1035 dodań i 0 usunięć

23
inch/manifest.json 100755
Wyświetl plik

@ -0,0 +1,23 @@
{
"manifest_version": 3,
"version": "0.2",
"name": "AI Noise-cancelling headphones",
"author": "jacob@thinkst.com",
"description": "An extension to filter out AI-generated noise from your browsing experience",
"permissions": [
"contextMenus",
"storage"
],
"content_scripts": [
{
"js": ["scripts/nch.js"],
"matches": [
"*://*/*"
]
}
],
"background": {
"service_worker": "scripts/nch-worker.js"
}
}

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -0,0 +1,59 @@
/*
Noise-cancelling headphones for the internet
(C) 2023 Thinkst Applied Research
Author: Jacob Torrey
This extension classifies all the text in every <p> on a page using a fast LZMA-based LLM-detector model.
It sets the opacity of the <p> to the confidence that the <p> is human-written, so LLM-generated content
fades away.
*/
// Import the other background service worker code
importScripts('lzma_worker-min.js');
importScripts('nlzmadetect.js');
const CONTEXT_MENU_ID = 'NCH_CONTEXT_MENU';
function ext_add_to_lp(info, _tab) {
if (info.menuItemId != CONTEXT_MENU_ID)
return;
//console.log("Adding to LP: " + info.selectionText);
add_to_lp(info.selectionText);
chrome.storage.local.set({lp: local_prelude});
}
chrome.contextMenus.removeAll();
chrome.contextMenus.create({
title: "Add text as AI-generated",
contexts: ["selection"],
id: CONTEXT_MENU_ID
});
chrome.contextMenus.onClicked.addListener(ext_add_to_lp)
chrome.storage.local.get(["lp"], function(val) {
if ("lp" in val)
local_prelude = val.lp;
});
// How much to boost or decrease the scores
const skew_factor = 0.9
// Function to analyze text for its origin
async function query(text) {
var score = detect_string(text);
if (score == 1)
return 1;
return score / skew_factor;
}
// Tracking tabs that are dead to avoid sending responses to.
var send_errs = 0;
async function return_results(tab, id, score) {
const msg = {id: id, opacity: score};
chrome.tabs.sendMessage(tab, msg, {}, function(res) { if (chrome.runtime.lastError) send_errs++; });
}
function handle_req(msg, sender, _sendResp) {
query(msg.content).then((score) => { if (score != 1) return_results(sender.tab.id, msg.id, score) });
}
chrome.runtime.onMessage.addListener(handle_req);

Wyświetl plik

@ -0,0 +1,41 @@
/*
Noise-cancelling headphones for the internet
(C) 2023 Thinkst Applied Research
Author: Jacob Torrey
This extension classifies all the text in every <p> on a page using a fast LZMA-based LLM-detector model.
It sets the opacity of the <p> to the confidence that the <p> is human-written, so LLM-generated content
fades away.
*/
// Sends content to the web worker in the extension to process the text
async function send_request(id, text) {
const msg = {id: id, content: text};
chrome.runtime.sendMessage(msg);
}
// Given a JSON msg with the ID and opacity, sets the opacity as specified.
function set_opacity(msg, _sender, _sendResp) {
var element = document.getElementById(msg.id);
if (element) {
//console.log("Setting " + element.id + " to opacity: " + msg.opacity);
const opacity = Math.round(msg.opacity * 100) / 100;
element.style.transition = "color 1s ease-out";
element.style.color = "rgba(0, 0, 0, " + opacity + ")";
}
}
chrome.runtime.onMessage.addListener(set_opacity);
// The types of elements we'll iterate through
const selector = 'p';
const tags = document.querySelectorAll(selector);
tags.forEach(element => {
if (element.textContent && element.textContent.length >= 150) {
// Make sure there's an id for that element to later set the opacity
if (element.id == "")
element.id = 'id' + selector + Math.floor(Math.random() * 1000).toString();
send_request(element.id, element.textContent);
}
});

File diff suppressed because one or more lines are too long