Skip to content

Instantly share code, notes, and snippets.

@maciejjankowski
Created September 27, 2019 21:05
Show Gist options
  • Save maciejjankowski/a5d463c2476059c717639e5e683d4548 to your computer and use it in GitHub Desktop.
Save maciejjankowski/a5d463c2476059c717639e5e683d4548 to your computer and use it in GitHub Desktop.
github bookmarking bookmarklet
const month = new Date().toDateString().split(' ')[1];
const year = new Date().toDateString().split(' ')[3];
if (location.href.indexOf(`github.com/maciejjankowski/${year}/wiki`) > -1) {
const searchToken = '# Worth checking:\n';
const textarea = document.querySelector('#gollum-editor-body');
const textIndex = textarea.value.indexOf(searchToken);
const textLength = searchToken.length;
textarea.value =
textarea.value.slice(0, textIndex + textLength) +
prompt() +
textarea.value.slice(textIndex + textLength);
document.querySelector('#gollum-editor-submit').click();
} else {
prompt(
'',
(function() {
let header = (
document.querySelector('h1') ||
document.querySelector('h2') || { innerText: document.title }
).innerText;
let address = window.location.href;
return `* [${header}](${address})`;
})()
);
window.location.href = `https://github.com/maciejjankowski/${year}/wiki/${month}/_edit`;
void 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment