Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:((config, menuId, wrapper, popup) => {
- /* Bookmarklets Menu
- Version: 1.0.1
- License: AGPL v2
- Author : jcunews
- Sites : https://www.reddit.com/user/jcunews1
- https://greasyfork.org/en/users/85671-jcunews
- https://pastebin.com/u/jcunews
- https://gist.github.com/jcunews
- Example of a bookmarklet menu containing other bookmarklets. Use it as a code template.
- Note:
- Clicking on the darkened area outside of the menu, or running the bokomarklet while the menu is being shown, will close the menu.
- A bookmarklet code should not contain any line based comment as the code will be collapsed into a single line since it's an URL.
- The length of the bookmarklet's URL should not be greater than 65535 UTF-16 characters.
- A release and proven stable code should omit any comment and compact/compress/uglify the code, to minimize the URL length.
- It's recommended to keep development and release code separate.
- */
- /* bookmarklet menu code */
- if (navigator.userAgent.includes("Firefox/") && document.contentType.endsWith("/xml")) return alert("Bookmarklet menu is disabled on XML content in Firefox.");
- if (wrapper = window[menuId = config.menuId]) return wrapper.remove();
- document.documentElement.insertAdjacentHTML("beforeend", `
- <div id="${menuId}">
- <style>
- #${menuId},#${menuId} *{all:revert;margin:0;box-sizing:border-box}
- #${menuId}{position:fixed;left:0;top:0;width:100vw;height:100vh;background:#0005;line-height:1.5em;font-family:sans-serif;cursor:pointer}
- #${menuId} .bookmarkletMenu{position:fixed;left:50%;top:50%;transform:translate(-50%, -50%);border:1px solid #555;background:#eee;cursor:default}
- #${menuId} .bookmarkletMenu>*{display:block;padding:0 .3em}
- #${menuId} h4{background:#777;color:#fff}
- #${menuId} .separator{border-top:1px solid #555}
- #${menuId} a:hover{background:#007;color:#fff}
- </style>
- <div class="bookmarkletMenu"></div>
- </div>`
- );
- (wrapper = window[menuId]).onclick = ev => ev.target.id && wrapper.remove();
- popup = wrapper.lastElementChild;
- if (config.menuTitle) popup.appendChild(document.createElement("H4")).textContent = config.menuTitle;
- config.menuItems.forEach((item, ele) => {
- popup.appendChild(ele = document.createElement("A")).textContent = item.title;
- if (item.separatorBefore) ele.classList.add("separator");
- ele.onclick = () => (wrapper.remove(), item.code(), false)
- });
- document.documentElement.focus()
- })(
- /* bookmarklet menu configuration */
- {
- /* menu unique ID. to prevent same menu from appearing twice.
- must not conflict with a name of anything, and must not contain any white-space or below characters:
- ~ @ # * + [ ] { } : ; \ , .
- */
- menuId: "myBookmarklets-123987",
- /* menu title. use empty string to disable */
- menuTitle: "My Bookmarklets",
- /* one or more bookmarklet menu item objects which contain title, and code */
- menuItems: [
- {
- title: "Bookmarklet #1",
- code: () => {
- alert("this is bookmarklet #1")
- }
- },
- {
- title: "Bookmarklet #2",
- code: () => {
- alert("this is bookmarklet #2")
- }
- },
- {
- title: "Bookmarklet #3: Go to Bing",
- code: () => {
- location.href = "https://www.bing.com/"
- },
- separatorBefore: true /* optional setting to display horizontal menu separator before this menu item */
- }
- /* and so on... */
- ]
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement