Last active
March 15, 2023 17:42
-
-
Save oaustegard/055dab3b917b7ede0f4462056b61522c to your computer and use it in GitHub Desktop.
Bookmarklets
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 () { | |
if (typeof turndownService === 'undefined') { | |
const script = document.createElement('script'); | |
script.onload = function () { | |
convertSelectedHtmlToMarkdown(); | |
}; | |
script.src = 'https://cdn.jsdelivr.net/npm/turndown/dist/turndown.js'; | |
document.head.appendChild(script); | |
} else { | |
convertSelectedHtmlToMarkdown(); | |
} | |
function convertSelectedHtmlToMarkdown() { | |
const html = window.getSelection().toString(); | |
const div = document.createElement('div'); | |
div.innerHTML = html.trim(); | |
const turndownService = new TurndownService(); | |
const md = turndownService.turndown(div.innerHTML); | |
navigator.clipboard.writeText(md); | |
alert('Copied HTML as Markdown to clipboard!'); | |
} | |
})(); |
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() { | |
let url = window.location.href; | |
let key = AJS.$('#key-val').text(); | |
let summary = AJS.$('#summary-val').text().trim(); | |
let status = AJS.$('#status-val span').text().trim(); | |
let resolution = AJS.$('#resolution-val').text().trim(); | |
let priority = AJS.$('#priority-val').text().trim(); | |
let type = AJS.$('#type-val').text().trim(); | |
let assignee = AJS.$('#assignee-val').text().trim(); | |
status = status || resolution || ""; | |
let markdownLink = "[" + key + "](" + url + ")"; | |
let description = summary + " (" + status + "/" + priority + "/" + type + "/" + assignee + ")"; | |
let markdown = "_" + markdownLink + " - " + description + "_"; | |
let textarea = document.createElement('textarea'); | |
textarea.textContent = markdown; | |
document.body.appendChild(textarea); | |
textarea.select(); | |
document.execCommand('copy'); | |
textarea.remove(); | |
})(); | |
/*alert('Markdown link and description copied to clipboard!');*/ | |
/* Example output: | |
_[SWP-34075](http://backstrom.meso-scale.com/jira/browse/SWP-34075) - 4.0 Remaining Web Work (In Progress/Major/Epic/Prabhu, Arvind)_ | |
*/ |
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(){ | |
const linkText = document.title; | |
const linkUrl = location.href; | |
const postBody = document.querySelector('meta[property="og:description"]').content; | |
const postTime = document.querySelector('meta[property="og:published_time"]').content; | |
const markdown = `[${linkText}](${linkUrl})\n\n>${postBody}\n>*${postTime}*`; | |
navigator.clipboard.writeText(markdown); | |
alert("Markdown preview copied to clipboard!"); | |
})(); |
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 () { | |
const urlRegex = /^https?:\/\/twitter\.com\/.+\/status\/\d+/; | |
const titleRegex = /^(.+) on Twitter: "(.+)" \/ Twitter$/; | |
const url = window.location.href; | |
const title = window.document.title; | |
if (!urlRegex.test(url)) { | |
alert("This bookmarklet only works on Twitter tweet pages"); | |
return; | |
} | |
const match = title.match(titleRegex); | |
const personName = match[1]; | |
const tweetBody = match[2].replace(/https?:\/\/t\.co\/\w+/, "").trim(); | |
const markdown = `[${personName} on Twitter:](${url})\n> ${tweetBody}`; | |
navigator.clipboard.writeText(markdown); | |
alert("Converted tweet to markdown and copied to clipboard!"); | |
})(); |
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: | |
void(function() { | |
/* Get current location and page title */ | |
loc = window.location; | |
page_title = window.document.title; | |
/* Create a new window with a form */ | |
w = window.open(null, null, "height=150,width=900"); | |
d = w.document; | |
d.open(); | |
d.write(`<html><head><title>Create formatted link</title></head> | |
<body> | |
<form onsubmit="return false"> | |
<table> | |
<tr><th>URL: </th><td><input id="url" type="text" size="100"></td></tr> | |
<tr><th>Link title:</th><td><input id="title" type="text" size="100"></td></tr> | |
<tr><td/><td><input id="copy" type="submit" value="Copy & Close"/></td></tr> | |
</table> | |
</form> | |
</body></html>`); | |
/* Get form elements */ | |
l = d.getElementById("url"); | |
t = d.getElementById("title"); | |
c = d.getElementById("copy"); | |
/* Set form values */ | |
l.value = window.location.toString(); | |
t.value = page_title; | |
/* Function to copy both HTML and plain text to clipboard */ | |
function copyToClip(doc, html, text = null) { | |
function listener(e) { | |
e.clipboardData.setData("text/html", html); | |
e.clipboardData.setData("text/plain", text || html); | |
e.preventDefault(); | |
} | |
doc.addEventListener("copy", listener); | |
doc.execCommand("copy"); | |
doc.removeEventListener("copy", listener); | |
}; | |
/* On click, copy link and close window */ | |
c.onclick = function() { | |
e = d.createElement("a"); | |
e.href = l.value; | |
e.innerHTML = t.value; | |
mdlink = `[${t.value}](${l.value})`; | |
copyToClip(d, e.outerHTML, mdlink); | |
w.close(); | |
}; | |
/* Close document and focus on 'Copy & Close' button */ | |
d.close(); | |
c.focus(); | |
}) () |
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() { | |
const githubAccessToken = 'github_pat_here'; | |
const dom = document.querySelector('main > .flex-1 > .h-full .flex:has(> .w-full)'); | |
const template = document.createElement('template'); | |
template.innerHTML = dom.innerHTML; | |
['.items-end', 'img', 'svg', 'button', ':empty'].forEach(selector => { | |
template.content.querySelectorAll(selector).forEach(node => { | |
node.remove(); | |
}); | |
}); | |
const title = document.title.replace(/[^a-z0-9]/gi, '_'); | |
const content = `<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Chat GPT: ${title}</title> | |
<meta name="generator" content="chatGPT Saving Bookmark"/> | |
<style> | |
body { | |
background-color: rgb(32,33,35); | |
color: rgb(236,236,241); | |
font-size: 20px; | |
font-family: Calibri,Arial, sans-serif; | |
margin: -10px; | |
} | |
body > .w-full { | |
padding: 40px; | |
} | |
/* prompt */ | |
body > .w-full:nth-child(2n+1) { | |
background: rgb(52,53,65); | |
} | |
/* response */ | |
body > .w-full:nth-child(2n+2) { | |
background: rgb(68,70,84); | |
} | |
.whitespace-pre-wrap { | |
white-space: pre-wrap; | |
} | |
.flex-col { | |
max-width: 1000px; | |
margin: 0px auto; | |
} | |
</style> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/styles/default.min.css"/> | |
</head> | |
<body>${template.innerHTML}</body> | |
</html>`; | |
const gistDescription = `Chat GPT transcript: ${title}`; | |
const gistFilename = `${title}.html`; | |
const gistContent = {}; | |
gistContent[gistFilename] = { content }; | |
const data = { | |
description: gistDescription, | |
public: false, | |
files: gistContent, | |
}; | |
fetch('https://api.github.com/gists', { | |
method: 'POST', | |
headers: { | |
'Authorization': `token ${githubAccessToken}`, | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify(data), | |
}) | |
.then(response => response.json()) | |
.then(gist => { | |
const gistId = gist.id; | |
const previewUrl = `https://austegard.com/pv?${gistId}`; | |
navigator.clipboard.writeText(previewUrl).then(() => { | |
console.log('Preview url copied to clipboard:', previewUrl); | |
}).catch(error => { | |
console.error('Failed to copy preview url to clipboard:', error); | |
}); | |
window.open(previewUrl); | |
}) | |
.catch(error => { | |
console.error(error); | |
alert('An error occurred while creating the Gist.'); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment