Skip to content

Instantly share code, notes, and snippets.

@gyuque
Created November 10, 2012 13:37
Show Gist options
  • Save gyuque/4051073 to your computer and use it in GitHub Desktop.
Save gyuque/4051073 to your computer and use it in GitHub Desktop.
全部いいね
// ==UserScript==
// @name autoiine
// @namespace gyuque
// @description 全部いいね
// @include http://www.facebook.com/*
// @include https://www.facebook.com/*
// @version 1
// @grant none
// ==/UserScript==
(function() {
'use strict';
function eachElement(tagName, func) {
var ls = document.getElementsByTagName(tagName);
var len = ls.length;
for (var i = 0;i < len;++i) {
func(ls[i]);
}
}
function clickLike(el) {
if (el.firstChild && el.firstChild.nodeValue) {
if (el.firstChild.nodeValue.match(/いいね!$/)) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, unsafeWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
}
}
}
function setup() {
var btn = document.createElement("button");
btn.innerHTML = "全部いいね";
document.body.appendChild(btn);
btn.addEventListener("click", eachElement.bind(null, 'a', clickLike), false);
var s = btn.style;
s.position = "absolute";
s.top = "40px";
s.left = "4px";
s.zIndex = "100";
}
setup();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment