1

I'm looking to create a bookmarklet that will modify any URLs that are created using the wordpress editor when creating a new post. This javascript/bookmarklet will add a string of code such as ?=2324 after any URL found in the post. a link to google.com will become google.com?=2324. The element ID for the form is textarea#content.wp-editor-area.

Is this possible?

1 Answers1

2

First, add any bookmark. Then right-click on it and click on properties. Specify a name.

Then for the url, write:

javascript:var toChange=document.getElementById("content");var re=/("|')https?:\/\/*("|')/gi;toChange.value=toChange.replace(re,function($0){return $0+"?=234";});void(0)

If there is an error, tell it to me.

Alexandre Khoury
  • 3,896
  • 5
  • 37
  • 58
  • That is the concept i need but the bookmarklet needs to actually edit the hyperlinks in the WYSIWIG editor of wordpress. Like a find and replace. Then once the post is saved, it can be viewed and all hyperlinks will have ?=2324 added to them. Thank you thus far! – DirkDiggler Jul 09 '12 at 19:20
  • I don't know a lot wordpress, maybe if you describe me how it is and the `id` of the textarea... – Alexandre Khoury Jul 09 '12 at 19:26
  • wordpress uses a WYSYWIG editor. See screenshot http://i.imgur.com/iy2RY.png. An ideal bookmarklet would find locate the URL in the WYSIWIG editor as http://* and append the =?232 to the URL. – DirkDiggler Jul 09 '12 at 19:39
  • does not work as a bookmarklet either. same error in console. – DirkDiggler Jul 09 '12 at 20:12
  • @user1512806 Is the WYSIWIG in an iframe? – Alexandre Khoury Jul 10 '12 at 17:00
  • I'm don't think so, i see iframe, but that might be for the media uploader. Here is the page source: http://pastebin.com/UJhUFRsw – DirkDiggler Jul 10 '12 at 17:53
  • hey Mageek. Thank you for the help so far! I have some working code and created a new question. Please see. http://stackoverflow.com/questions/11422274/jquery-to-identify-url-and-append-parameters – DirkDiggler Jul 10 '12 at 21:29
  • @user1512806 If Mageek's answer helped solve your problem, you should give his answer an upvote and mark it as the accepted answer. This helps other people who may be having a similar issue find solutions that may work for them as well. – Jason Towne Jul 10 '12 at 22:36