Created
November 8, 2012 12:10
-
-
Save gyuque/4038429 to your computer and use it in GitHub Desktop.
全部favるやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name milkyway | |
// @namespace gyuque | |
// @include https://twitter.com/* | |
// @include http://twitter.com/* | |
// @version 2 | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function eachFavBox(func) { | |
var ls = document.getElementsByClassName("favorite"); | |
var len = ls.length; | |
for (var i = 0;i < len;++i) { | |
var box = ls[i]; | |
func(box); | |
} | |
} | |
function findFavorited(el) { | |
for (var i = 0;i < 8;++i) { | |
el = el.parentNode; | |
if (el && el.className) { | |
if (el.className.indexOf("tweet") >= 0 && el.className.indexOf("favorited") >= 0) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
function forceClick(el) { | |
if (findFavorited(el)) { | |
return; | |
} | |
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 = "全fav"; | |
btn.addEventListener("click", eachFavBox.bind(null, forceClick), false); | |
var s = btn.style; | |
s.position = "absolute"; | |
s.top = "45px"; | |
s.right = 0; | |
document.body.appendChild(btn); | |
} | |
setup(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment