I’m writing a userscript that inserts an element onto the tumblr dashboard and populates it with a user’s tracked tags as pulled from another portion of the page. Though my script seems like it should be working, so far all I’ve gotten it to do is create the element; the element’s contents never populate.
var jQuery, $ = null;
function addJQuery(callback) {
var p = null;
if(window.opera || window.navigator.vendor.match(/Google/)) {
var div = document.createElement("div");
div.setAttribute("onclick", "return window;");
p = div.onclick();
}
else {
p = unsafeWindow;
}
jQuery = $ = p.jQuery.noConflict();
callback();
}
var myFunction = function() {
jQuery('div#right_column ul#dashboard_controls_open_blog').after('<ul class="controls_section" id="tracked_tags"></ul>');
jQuery('div.tracked_tags a').each(function (i) {
var tagID = jQuery(this).attr(id);
var tagIDNumber = tagID.replace('tag_','');
var tagName = jQuery(this).attr(href);
var tagNameClean = tagName.replace('/tagged/','');
var tagContent ='';
tagContent += '<a href="'+tagName+'" id="'+tagID+'" class="tag">';
tagContent += '<div class="hide_overflow">'+tagNameClean+'</div>';
tagContent += '<span id="tag_unread_'+tagIDNumber+'" class="count" style=""></span></a>';
tagContent += '<a class="sub_control" id="track_'+tagIDNumber+'" style="display:none;" onclick="track_tag('+tagIDNumber+', "n4av5kz9baBCv1PRCPUlT8X5K8", false);return false;">track</a>';
tagContent += '<div class="remove_tag" id="untrack_'+tagIDNumber+'" onclick="if (confirm("Stop tracking this tag?")) {track_tag('+tagIDNumber+', "n4av5kz9baBCv1PRCPUlT8X5K8", true);} return false;">*</div>';
tagContent += '<div id="tag_loader_'+tagIDNumber+'" class="tracked_tag_loader" style="display:none;"></div></li>';
//tagContent += '<script type="text/javascript">new Effect.Appear("tag_unread_'+tagIDNumber+'");</script>';
jQuery(tagContent).appendTo('div#right_column ul#tracked_tags');
alert(tagID);
});
};
addJQuery(myFunction);
Here’s the script on JSFiddle with the HTML I’m working with included as well. Any help would be appreciated.
JSFiddle was very helpful, so I have found several errors in your script. Generally, javascript in hrefs was not properly escaped. Also, you appended to wrong element.
You can see it working.