ReedyBear's Blog

BearBlog: Edit the post you are currently viewing

USE MY NEW SOLUTION: Edit Current Post button for BearBlog


Create a bookmark in your browser with the name "Edit Post" and url set to the old or new javascript code.

November 5th Solution

The Analytics code had been updated to use shape-outside instead of border-image, and this solution fixed that. This solution is now broken because there is a new javascript-based analytics code. Non-discoverable posts do not have HTML markup indicating their post ID, so I have to copy it from the analytics code in order to generate the link to edit the post.

javascript:  
username="YOUR_USERNAME";  
use_new_tab=false;  
/** gets the post's id from the analytics CSS */  
function get_post_id(){  
    f='shape-outside: url("/hit/';  
    h=document.head.innerHTML;  
    id=h.substring(h.indexOf(f)+f.length);  
    id=id.substr(0,id.indexOf('/'));  
    return id;  
}  
/* gets the post id from the html markup of discoverable posts, or calls get_post_id() */  
post_id = document.querySelector('[name=uid]')?.value??get_post_id();  
/* Check if it's the home page */  
if (window.location.pathname == '/')path = "/dashboard/";  
else path = "/dashboard/posts/"+post_id+"/";  
/* open the edit post page */  
window.open("https://bearblog.dev/"+username+path, use_new_tab?"_blank":"_self");  

NEW CODE

The old code didn't let you edit pages that had make_discoverable:false in the header.

Replace YOUR_USERNAME with yours. Mine's 'reedybear' like my subdomain.

javascript:username="YOUR_USERNAME";function get_post_id(){f='border-image: url("/hit/';h=document.head.innerHTML;id=h.substring(h.indexOf(f)+f.length);id=id.substr(0,id.indexOf('/'));return id;}window.open("https://bearblog.dev/"+username+"/dashboard/posts/"+(document.querySelector('[name=uid]')?.value??get_post_id())+"/", "_self");  

OLD CODE

replace {YOUR_USER_NAME}

javascript:window.open("https://bearblog.dev/{YOUR_USER_NAME}/dashboard/posts/"+document.querySelector('[name=uid]').value+"/", "_self")  

If you're on your bearblog dashboard, you'll see your username in the URL.

Old Code Explanation

javascript:  // Tells the bookmark to run javascript  
window.open(  // open a url  
    "https://bearblog.dev/{YOUR_USER_NAME}/dashboard/posts/"  
     + document.querySelector('[name=uid]') // select a hiddden element on the page       
     .value  // get your unique id from the element (it's part of the URL)  
     +"/", // Ends the URL that is being opened  
     "_self" // Tells the browser to open the url in the current tab. Use "_blank" for new tab  
)  

New Code Explanation

Discoverable pages have a uid printed as a value on an HTML Node. non-discoverable pages only print the uid in some CSS as part of the analytics for Bear. So I have to find that CSS code block & cut the uid of the post out of it. I define a function get_post_id() that gets this uid out of the CSS code & returns it. I still look for that html node with the uid, and then call get_post_id() if that node doesn't exist.

I'm not doing a line-by-line breakdown, though.

#bearblog