Last active
January 22, 2025 00:50
-
-
Save volkanunsal/5c746b264fb66dc2f051ba277333d24b to your computer and use it in GitHub Desktop.
Summarizes a text using built-in Chrome AI LLM -- Gemini Nano
This file contains 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
// ==UserScript== | |
// @name Summarize Script | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Summarize page | |
// @author Volkan Unsal | |
// @match *://*/* | |
// @grant GM_registerMenuCommand | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function injectModule(src) { | |
var scriptId = src.split('/').pop().split('.').shift(); | |
if (document.getElementById(scriptId)) { | |
return; | |
} | |
var script = document.createElement('script'); | |
script.id = scriptId; | |
script.src = src; | |
return new Promise(resolve => { | |
document.head.appendChild(script); | |
script.onload = resolve; | |
}) | |
} | |
function runFastBookmark() { | |
var documentClone = document.cloneNode(true); | |
injectModule('https://cdn.jsdelivr.net/npm/@mozilla/[email protected]/Readability.min.js').then(() => { | |
let article = new Readability(documentClone).parse(); | |
ai.summarizer.create({ type: 'tl;dr', format: 'plain-text' }).then(a => { | |
a.summarize(article.textContent.slice(0, 2000)).then(summary => { | |
console.log(summary); | |
}); | |
}); | |
}) | |
} | |
// Add a menu button to trigger the script | |
GM_registerMenuCommand('Run Summarizer', runFastBookmark); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment