-
-
Save DerKobe/d07b43b4f3d7ee9bcb7efa05d8ece979 to your computer and use it in GitHub Desktop.
highlight and drag this code into your bookmark bar. If that doesn't work, ask chatGPT how to make a bookmarklet
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
javascript:(function() { | |
function extractText(element) { | |
if (element.nodeType === Node.TEXT_NODE) { | |
return element.textContent.trim() + ' '; | |
} | |
if (element.nodeType !== Node.ELEMENT_NODE) { | |
return ''; | |
} | |
let text = ''; | |
for (const child of element.childNodes) { | |
text += extractText(child); | |
} | |
if (element.tagName.match(/^(H[1-6]|P|LI|DIV)$/)) { | |
text += '\n'; | |
} | |
return text; | |
} | |
function copyToClipboard(text) { | |
const textarea = document.createElement('textarea'); | |
textarea.style.position = 'fixed'; | |
textarea.style.opacity = '0'; | |
textarea.value = text; | |
document.body.appendChild(textarea); | |
textarea.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(textarea); | |
} | |
try { | |
const contentSelectors = ['article', '.article', '.post', '.entry', 'main', '.content']; | |
let articleElement = null; | |
for (const selector of contentSelectors) { | |
articleElement = document.querySelector(selector); | |
if (articleElement) { | |
break; | |
} | |
} | |
if (!articleElement) { | |
throw new Error('Article element not found'); | |
} | |
const text = extractText(articleElement); | |
const preamble = '[1] - Rewrite the article below to make it more informative, truth-focused, and neutral.\n[2] - Compare the original article to the rewrite, and describe the bias of the original, use a numbered list if needed\n\n'; | |
const clipboardText = preamble + text; | |
copyToClipboard(clipboardText); | |
alert('The article and a prompt have been copied to your clipboard. Please paste into ChatGPT to see through the spin.'); | |
} catch (error) { | |
const message = `Objective: Modify the bookmarklet to change the preamble and alert text. | |
Specification: | |
1) Optimize for news websites | |
2) Include headings and subheadings | |
3) Use a simple JavaScript alert for the popup | |
4) Update the preamble and alert text as specified | |
Error: ${error.message} | |
Source code of the bookmarklet: | |
${decodeURIComponent(window.location.href)} | |
Please help improve this code to prevent the error.`; | |
copyToClipboard(message); | |
alert('there was an error in execution. the prompt for this bookmarklet and the error message have been copied to your clipboard, you can paste them into chatGPT 4 to try and fix the problem\n\n If you make improvements, please submit them to https://gist.github.com/rynomad/2f79fd427dd420dcd71ecc7a59ed3a31/'); | |
} | |
})() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment