|
_bm_name = "Edit Bookmarklet"; |
|
_bm_id = location.href; |
|
_bm_window = window.open("", _bm_name, "fullscreen=no,height=150,left=50,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,top=50,width=100"); |
|
_bm_edit = function() { |
|
window.focus(); |
|
document.body.contentEditable = true; |
|
document.designMode = true; |
|
alert("Editing..."); |
|
_bm_window.focus(); |
|
}; |
|
_bm_save = function() { |
|
if (!_bm_window.confirm("Are you sure you want to save? This will overwrite other saves for this page.")) return; |
|
document.body.contentEditable = false; |
|
document.designMode = false; |
|
|
|
let pathparts = location.pathname.split("/"); |
|
let data = { |
|
body: document.body.innerHTML, |
|
url: pathparts[pathparts.length-1], |
|
title: document.title |
|
}; |
|
|
|
localStorage.setItem(_bm_name + " " + _bm_id, JSON.stringify(data)); |
|
_bm_window.alert("Changes Saved"); |
|
_bm_window.focus(); |
|
}; |
|
_bm_load = function() { |
|
|
|
let data = JSON.parse(localStorage.getItem(_bm_name + " " + _bm_id)); |
|
|
|
document.body.innerHTML = data.body; |
|
document.title = data.title; |
|
history.pushState({yoda:true}, "", data.url); |
|
|
|
_bm_window.alert("Changes Loaded"); |
|
_bm_window.focus(); |
|
}; |
|
_bm_find_replace = function() { |
|
let a = _bm_window.prompt("Replace all instances of:"); |
|
let b = _bm_window.prompt("with:"); |
|
document.body.innerHTML = document.body.innerHTML.replaceAll(a,b); |
|
_bm_window.alert("Done!"); |
|
_bm_window.focus(); |
|
}; |
|
_bm_title = function() { |
|
document.title = _bm_window.prompt("Title:"); |
|
}; |
|
_bm_path = function() { |
|
window.focus(); |
|
history.pushState({yoda:false}, "", prompt("New URL path?")); |
|
}; |
|
|
|
function _bm_start() { |
|
if (typeof _bm_open !== 'undefined') return; |
|
_bm_window.document.write(` |
|
<body style='font-family:monospace;text-align:center'> |
|
<b>${_bm_name}</b><br><br> |
|
<a href='#' onclick='opener._bm_edit()'>edit</a> |
|
<a href='#' onclick='opener._bm_save()'>save</a> |
|
<a href='#' onclick='opener._bm_load()'>load</a> |
|
<br><br> |
|
<a href='#' onclick='opener._bm_find_replace()'>find & replace</a><br> |
|
<a href='#' onclick='opener._bm_title()'>set title</a><br> |
|
<a href='#' onclick='opener._bm_path()'>set URL</a> |
|
</body>`); |
|
_bm_window.onunload = function() {delete _bm_open}; |
|
window.onunload = function() { |
|
_bm_window.close(); |
|
history.pushState({yoda:"maybe"}, _bm_id); |
|
}; |
|
_bm_open = true; |
|
} |
|
_bm_start(); |