Skip to main content

https://petermolnar.net/press-this-indieweb/I've been able to reply/like/repost with my site for a long while, but is wasn't elegant, fast or slick at all; it was time to fix it.

The lazier I want to get the more code I need to write, but in the end, it always worth it. Pfefferle had pre-baked a solution already but my theme is special so I had to come up with my own solution.

Me vs sanity
For a long while I manually copy pasted URLs into an additional post meta field in my WordPress, which I called webmention_url. When I wanted to reply I:

copied the URL
went over to my admin area
opened a new post
copied the URL to a post meta field
selected webmention type from the radiobutton
posted the reply
This was tedious, smelled redundant, and introduced a lot more work.

To show the URLs I had to add it in my theme - it wasn't part of the_content, so it wasn't showing in the RSS or in the mail I'm sending out to some.

I had to hook that post meta field into the webmention plugin and do other magic on it, which made all the things even more complicated.

Bookmarklets
To solve the copy-paste part I turned to Press This - which I used a long, long time ago, and when I wanted to use it now, it didn't work. Because Firefox.

To solve it:

about:config
security.csp.enable => false
This sacrificed some security, which I'm not proud of, but I'm tired of all the fresh things that break things we're actively using.

After this I realized, I need to pass the type of the webmention - so for reply, I added &type=reply at the end of the bookmarklet url, which now looks like this:

javascript:(function(a,b,c,d){function%20e(a,c){if("undefined"!=typeof%20c){var%20d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",p.appendChild(d)}}var%20f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return%20void(top.location.href=d);if(d+="&u="+o(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?h=a.getSelection()+"":b.getSelection?h=b.getSelection()+"":b.selection&&(h=b.selection.createRange().text||""),d+="&buster="+(new%20Date).getTime(),s||(b.title&&(d+="&t="+o(b.title.substr(0,256))),h&&(d+="&s="+o(h.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return%20void%20a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);i=q.getElementsByTagName("meta")||[];for(var%20t=0;t200);t++){var%20u=i[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");x&&(v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x))}j=q.getElementsByTagName("link")||[];for(var%20y=0;y=50);y++){var%20z=j[y],A=z.getAttribute("rel");("canonical"===A||"icon"===A||"shortlink"===A)&&e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(k=b.body.getElementsByClassName("hfeed")[0]),k=b.getElementById("content")||k||b.body,l=k.getElementsByTagName("img")||[];for(var%20B=0;B=100);B++)n=l[B],n.src.indexOf("avatar")>-1||n.className.indexOf("avatar")>-1||n.width&&n.width

Peter Molnar, Aug 17 2016 on stream.boffosocko.com