Skip to content

Commit

Permalink
button placed in header
Browse files Browse the repository at this point in the history
  • Loading branch information
whitered committed Dec 21, 2011
1 parent c0862d5 commit d955a0a
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions github-plus-one.user.js
Expand Up @@ -3,36 +3,42 @@
// @namespace ru.whitered
// @include http://github.com/*
// @include https://github.com/*
// @exclude http://github.com/
// @exclude https://github.com/
// @exclude http://github.com/*/*/*
// @exclude https://github.com/*/*/*
// @version 0.1
// @version 0.2
// ==/UserScript==

function getElementByXPath(expr, node)
{
return document.evaluate(expr, node, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

var button = document.createElement("g:plusone");
button.setAttribute("size", "medium");

var plusone = document.createElement("li");
plusone.setAttribute("class", "plusone");
plusone.appendChild(button);

var container = getElementByXPath("//ul[@class='pagehead-actions']", document);
container.insertBefore(plusone, container.firstChild);

var style = document.createElement("style");
style.type = "text/css";
style.innerHTML = "li.plusone>div { vertical-align: middle !important; }";
function insertPlusOne(node)
{
var button = document.createElement("g:plusone");
button.setAttribute("size", "small");
node.appendChild(button);

var po = document.createElement("script");
po.type = "text/javascript";
po.async = true;
po.src = "https://apis.google.com/js/plusone.js";

var po = document.createElement("script");
po.type = "text/javascript";
po.async = true;
po.src = "https://apis.google.com/js/plusone.js";
document.head.appendChild(po);
}

var head = document.head;
head.appendChild(po);
head.appendChild(style);
var pagehead = getElementByXPath("//ul[@class='pagehead-actions']", document);
if(pagehead)
{
var nodes = pagehead.parentNode.childNodes;
for (var i = 0; i < nodes.length; i++)
{
if(nodes[i].nodeType == 1)
{
insertPlusOne(nodes[i]);
break;
}
}
}

0 comments on commit d955a0a

Please sign in to comment.