Skip to content

Instantly share code, notes, and snippets.

@ashtonmeuser
Created February 2, 2025 01:44
Show Gist options
  • Save ashtonmeuser/a36be4b6c835276f1a22a8c49e54d6f0 to your computer and use it in GitHub Desktop.
Save ashtonmeuser/a36be4b6c835276f1a22a8c49e54d6f0 to your computer and use it in GitHub Desktop.
// bookmarklet-title: Stay Here
// bookmarklet-about: Prevent leaving current page. See https://river.me/blog/bookmarklet-stay-here/.
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
});
// bookmarklet-title: Twitter Search
// bookmarklet-about: Tweak Twitter's advances search syntax. See https://river.me/blog/firefox-keep-bookmark-keywords/.
(function () {
let s = "%s";
let url = "https://twitter.com/search?q=%s";
let l = {
all:'%s',
exact:'"%s"',
from:"(from:%s)",
any:"(%s)",
not:"-%s",
to:"(to:%s)",
mentions:"@%s",
hashtag:"(#%s)",
before:"until:%s",
after:"since:%s",
};
let chunks = url.split("%s");
let args = s.split("--");
let nurl = chunks[0];
let p = [];
for (j=1; j<args.length; j++) {
arg=args[j];
arg=arg.replace(/\^/g, " ");
w=arg.match(/\w+/);
arg=arg.replace(/\w+:/, "");
p.push(l[w].replace('%s', arg.trim()));
}
nurl += p.join(' ');
if (chunks[1]) nurl+= chunks[1];
location.replace(nurl, "< BR>");
})();
// bookmarklet-title: URL CLI
// bookmarklet-about: Keyword substitution. See https://river.me/blog/url-bar-is-a-cli/.
var s = "%s";
url = "https://%s.gamepedia.com/index.php?search=%s&title=Special:Search";
tt = [""];
j = 0;
qc = 0;
chunks = url.split("%s");
for (i = 0; i < s.length; i++) {
if (s.charAt(i) == "%22") qc = qc ^ 1;
if (s.charAt(i) == " " && (qc || j >= chunks.length - 2)) {
tt[j] += "^";
} else if (s.charAt(i) == " ") {
j++;
tt.push(" ");
} else {
tt[j] += s.charAt(i);
}
}
t = tt.join("");
args = t.split(/\s/);
nurl = "";
for (i = 0; i < chunks.length; i++) {
nurl += chunks[i];
if (args[i] != undefined) {
args[i] = args[i].replace(/\^/g, " ");
nurl += args[i];
}
}
location.replace(nurl, "< BR>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment