Skip to content

Instantly share code, notes, and snippets.

@TitusRobyK
Last active March 11, 2024 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TitusRobyK/992431b30423cbcaea206c897fc7f28a to your computer and use it in GitHub Desktop.
Save TitusRobyK/992431b30423cbcaea206c897fc7f28a to your computer and use it in GitHub Desktop.
##1 Performs a Wikipedia search on any highlighted text in the web browser window
javascript: (function() {
function se(d) {
return d.selection ? d.selection.createRange().text : d.getSelection()
}
var s = se(document);
for (var i = 0; i < frames.length && (s == null || s == ''); i++) s = se(frames[i].document);
if (!s || s == '') s = prompt('Enter%20search%20terms%20for%20Wikipedia', '');
open('https://en.wikipedia.org' + (s ? '/w/index.php?title=Special:Search&search=' + encodeURIComponent(s) : '')).focus();
})();
##2 A click-and-print solution that quickly adjusts a webpage's appearance for a cleaner printout
# and then changes everything back to normal once the printing is done.
javascript: (function() {
const originalStyle = document.body.getAttribute('style') || '';
const printStyle = 'height: auto; overflow: visible;';
document.body.setAttribute('style', printStyle);
window.print();
setTimeout(() => {
document.body.setAttribute('style', originalStyle);
}, 500);
})();
##3 Enable Copy-Paste in a webpage where its disabled.
javascript: (function() {
document.oncontextmenu = null;
document.body.oncopy = null;
document.body.oncut = null;
document.body.onpaste = null;
document.addEventListener('copy', function(e) {
e.stopPropagation();
}, true);
document.addEventListener('cut', function(e) {
e.stopPropagation();
}, true);
document.addEventListener('paste', function(e) {
e.stopPropagation();
}, true);
})();
##4 Instant Scratchpad or Notepad
data: text / html, < textarea style = "font-size: 1.25em; width: 100%; height: 100%;"autofocus / >
##5 Performs a Perplexity AI search on any highlighted text in the web browser window
javascript:(function() {
function se(d) {
return d.selection ? d.selection.createRange().text : d.getSelection()
}
var s = se(document);
for (var i = 0; i < frames.length && (s == null || s == ''); i++) {
s = se(frames[i].document);
}
if (!s || s == '') {
s = prompt('Enter search terms for Perplexity', '');
}
open('https://www.perplexity.ai' + (s ? '?q=What%20is%20' + encodeURIComponent(s) : '')).focus();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment