I'm using a bookmarklet script that publish the name and link of the website im browsing in plurk.com but that script will not allow me to edit it before is publish. Also it handles youtube links and flickr links but in their own way... im concerned in the function plurkText
Bookmarklet code that I'm using:
Is there a way to be able to edit the name of the link before is sent to plurk?Code:javascript: function plurk() { if (checkUrl()) { return true; } if (checkSelection()) { return true; } if (checkTitle()) { return true; } return false; } /* Check the url for patterns */ function checkUrl() { var matches; if (/^http:\/\/[a-z]+\.youtube\.com\/watch?/.test(window.location.href)) { var videoID = parameters()['v']; if (videoID) { plurkYoutubeVideo(videoID); return true; } } /* test flickr */ matches = /^http:\/\/(www\.)?flickr\.com\/photos\/([^\/]+)\/([0-9]+)/.exec(window.location.href); if (matches) { var username = matches[2]; var imageID = matches[3]; plurkFlickrImage(username, imageID); return true; } return false; } function checkSelection() { var selection = window.getSelection(); var selectionText = selection.toString(); if (selectionText.length > 0) { plurkText(selectionText); return true; } } function checkTitle() { var headTag = document.getElementsByTagName('head')[0]; if (!headTag) { return false; } var titleTag = headTag.getElementsByTagName('title')[0]; if (!titleTag) { return false; } var title = titleTag.textContent; if (title.length > 0) { plurkText(title); return true; } } function plurkYoutubeVideo(videoID) { /* TODO: fixa internationella sidor */ var videoUrl = "http://www.youtube.com/watch?v=" + videoID; /* create plurk */ var plurk = videoUrl; /* send the plurk */ sendPlurk(plurk, {}); } function plurkFlickrImage(username, imageID) { var photoUrl = "http://flickr.com/photos/" + username + "/" + imageID; var plurk = photoUrl; /* send the plurk */ sendPlurk(plurk, {}); } function plurkText(text) { var url = window.location; /* check title */ if (text.length == 0) { return false; } /* create plurk */ var plurk = url + " (" + text + ")"; /* send the plurk */ sendPlurk(plurk, {}); } function sendPlurk(message, options) { var now = new Date(); var parameters = { content: message + " ", posted: now.plurkify(), no_comments: Number(options['disableComments'] || false), lang: (options['language'] ||Â 'en'), qualifier: (options['verb'] || 'shares') }; var queryComponents = new Array(); for (var parameterName in parameters) { var parameterValue = parameters[parameterName]; if (parameterValue !== null) { queryComponents.push(parameterName + "=" + encodeURIComponent(parameterValue)); } } var query = queryComponents.join("&"); /* send query */ window.location = "http://www.plurk.com/addPlurk?" + query; } Date.prototype.plurkify = function() { return (this.getFullYear() + "-" + this.getDate() + "-" + (this.getMonth() + 1) + "T" + this.getHours().width(2) + ":" + this.getMinutes().width(2) + ":" + this.getSeconds().width(2)); } Number.prototype.width = function(width) { var stringRepresentation = this.toString(); /* split the string */ var matches = /^[+-]?([0-9]*)(\.[0-9]*)?$/.exec(stringRepresentation); /* calcultate the number of zeros to add */ var zerosNeeded = width - matches[1].length; if (zerosNeeded > 0) { /* add zeros before the string */ stringRepresentation = "0".repeat(zerosNeeded) + stringRepresentation; } return stringRepresentation; } Number.prototype.pad = function() { var stringRepresentation = this.toString(); if (stringRepresentation.length == 1) { stringRepresentation = '0' + stringRepresentation; } return stringRepresentation; } String.prototype.repeat = function(times) { var result = new String(); for (var count = 0; count < times; ++count) { result += this; } return result; } function parameters() { var query = window.location.search.slice(1); var parameterStrings = query.split('&'); var parameters = {}; for (var current = 0; current < parameterStrings.length; ++current) { var parameterString = parameterStrings[current]; var matches = /^([^=]+)=(.*)$/.exec(parameterString); if (matches) { parameters[matches[1]] = decodeURIComponent(matches[2]); } } return parameters } /* create and post plurk */ plurk();
This is the section that need to be edit... that's what I think...
Code:function plurkText(text) { var url = window.location; /* check title */ if (text.length == 0) { return false; } /* create plurk */ var plurk = url + " (" + text + ")"; /* send the plurk */ sendPlurk(plurk, {}); }


Reply With Quote

Bookmarks