Hi I've been trying to learn JS by messing around with Greasemonkey, tweaking peoples scripts and whatnot. Anyways I'm trying to add a "Like" button from Facebook to the first post of a thread. Yes I know there's the "Share This Thread!" link but like I said I'm using this merely as a self learning tool.
I think I have the code correct, but apparently not since it doesn't work.
Maybe someone here can help me out
Code:
// ==UserScript==
// @name MMOwned Like
// @namespace Dr. Watson
// @description Like a topic on MMOwned!
// @include http://www.mmowned.com/forums/*
// ==/UserScript==
base_url = getBaseURL();
var base_url = getBaseURL(window.location);
//HTML/CSS added to page
var like_html = '';
like_html = '<div style="float: left;"><iframe src="http://www.facebook.com/plugins/like.php?href=' + window.location + '&layout=box_count&show_faces=true&width=450&action=like&font=segoe+ui&colorscheme=dark&height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:65px;" allowTransparency="true"></iframe></div>';
output = document.createElement('div');
output.innerHTML = like_html;
//add HTML to id posthead
var op = document.getElementById('posthead');
op = op.getElementByTagName('a');
op = op.getElementByName('1');
if (op) {
op.parentNode.insertBefore(output, op.nextSibling);
}
//get url of thread
function getBaseURL () {
var url = location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));
if (baseURL.indexOf('http://localhost') != -1) {
var url = location.href;
var pathname = location.pathname;
var index1 = url.indexOf(pathname);
var index2 = url.indexOf("/", index1 + 1);
var baseLocalUrl = url.substr(0, index2);
return baseLocalUrl + "/";
}
else {
return baseURL + "/";
}
}