itty-bitty/docs/render/bookmarklet.js

31 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-02-15 23:28:50 +00:00
let url = params.body
let title = params.title
2022-05-18 05:36:38 +00:00
let ua = navigator.userAgent;
var b = document.documentElement;
b.setAttribute('data-useragent', navigator.userAgent);
b.setAttribute('data-platform', navigator.platform );
let mobile = ua.match(/Mobile/i)
let barName = ua.match(/Chrome/i) ? "Bookmarks" : "Favorites"
let managerName = ua.match(/Edge/i) ? "Favorites" : "Bookmarks"
let cmdKey = ua.match(/Mac/i) ? "⇧⌘B" : "Ctrl + Shift + B"
2022-06-17 04:48:00 +00:00
loadSyle(document.currentScript.src.replace("js", "css")).then(() => {
2022-05-18 05:36:38 +00:00
document.body.appendChild(
el("div", {id:"content"},
2022-05-20 16:49:38 +00:00
el("div", {className:"description"}, params.info?.d ?? ""),
2022-05-20 15:43:58 +00:00
el("a", {className:"bookmarklet", href:url}, el("span", {className:"capsule", innerText:"" + title || "Bookmarklet"})),
2022-05-20 15:37:00 +00:00
el("p", {id:"emoji", innerText:"☝️"}),
2022-05-18 05:36:38 +00:00
el("p", {innerHTML:`This page contains a <a target="_blank" href="https://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a>.`}),
el("p", {className:"", innerText:`Drag this bookmarklet to your ${managerName} to use it.`}),
el("p", {className:"hint desktop", innerText:`(Hit ${cmdKey} to toggle the ${managerName} bar)`}),
el("p", {className:"hint mobile", innerText:`To open ${managerName} while dragging, hold on top of it, or tap bookmarks with a second finger to open`}),
2022-05-20 16:49:38 +00:00
// el("p", {innerText:`Or bookmark this page, then edit the address to remove everything to the left of "javascript:"`}),
2022-05-18 05:36:38 +00:00
)
);
2022-06-17 04:48:00 +00:00
})