Created
October 4, 2010 12:48
-
-
Save teramako/609642 to your computer and use it in GitHub Desktop.
Firefox 4以上が対象。リンクが多いとハング歯科寝ないので注意
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 linkLarger | |
// @namespace http://gist.github.com/teramako/ | |
// @description リンクを大きくするお!! 【注意】超重たい | |
// @include http://* | |
// ==/UserScript== | |
const C = "linkLarger-link"; | |
GM_addStyle(<><![CDATA[ | |
.linkLarger-link { | |
-moz-transition-property: font-size !important; | |
-moz-transition-duration: 0.3s !important; | |
font-size: 300% !important; | |
} | |
]]></>.toString()); | |
function getAnchors() { | |
var a = document.getElementsByTagName("a"); | |
for (let i=0, elm; elm = a[i]; i++){ | |
if (elm.classList.contains(C)){ | |
elm.classList.remove(C); | |
} | |
yield elm; | |
} | |
} | |
function getTop3NearAnchor(x, y) { | |
var ds = []; | |
for (let elm in getAnchors()) { | |
let {bottom: bottom, top: top, height: height, left: left, right: right, width: width} = elm.getBoundingClientRect(); | |
if (bottom < 0 || top < 0 || left < 0 || width < 0) | |
continue; | |
let elmX = left + width / 2, | |
elmY = top + height / 2; | |
let d = Math.sqrt(Math.pow(x - elmX, 2) + Math.pow(y - elmY, 2)); | |
ds.push([d, elm]); | |
} | |
ds.sort(function(a, b) a[0] - b[0]); | |
return ds.slice(0, 3); | |
} | |
for (let elm in getAnchors()){ | |
elm.style.MozTransitionProperty = "font-size"; | |
elm.style.MozTransitionDuration = "0.5s"; | |
elm.style.fontSize = window.getComputedStyle(elm,"").fontSize; | |
} | |
document.addEventListener("mousemove", function(event) { | |
getTop3NearAnchor(event.pageX, event.pageY).forEach(function($_){ | |
let elm = $_[1]; | |
elm.classList.add(C); | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment