Last active
June 24, 2020 03:09
-
-
Save epser/435a6bc6271fa63a467c1f1e3851a04d to your computer and use it in GitHub Desktop.
Webページのホイール操作が勝手にスムーススクロール(余韻スクロール)になるのを止めるUserScript(TamperMonkey)
This file contains 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 Anti MouseWheelEvent Killer | |
// @description blocking window.mousewheel events | |
// @namespace https://gist.github.com/epser/ | |
// @version 0.26 | |
// @author eps_r | |
// @include http://*/* | |
// @include https://*/* | |
// @exclude http://*.google.com/* | |
// @exclude https://*.google.com/* | |
// @exclude https://*.amazon.com/* | |
// @exclude https://*.amazon.co.jp/* | |
// @exclude https://twitter.com/* | |
// @exclude https://*.twitter.com/* | |
// @grant none | |
// @updateURL https://gist.githubusercontent.com/epser/435a6bc6271fa63a467c1f1e3851a04d/raw/anti_mousewheelevent_killer.user.js | |
// @downloadURL https://gist.githubusercontent.com/epser/435a6bc6271fa63a467c1f1e3851a04d/raw/anti_mousewheelevent_killer.user.js | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let fuck = function(add, name) { | |
return function() { | |
if(arguments[0].match(/^(mousewheel|wheel|onmousewheel|onwheel|DOMMouseScroll)$/)) { | |
console.debug("Blocked: " + name + "." + arguments[0]); | |
// fix "overflow: hidden" pages(restore scroll) | |
['DOMContentLoaded', 'load'].forEach( (timing) => { | |
window.addEventListener(timing, function() { | |
document.querySelector('html').style.setProperty('overflow', 'auto', 'important'); | |
document.querySelector('body').style.setProperty('overflow', 'auto', 'important'); | |
}); | |
}); | |
} else { | |
add.apply(this, arguments); | |
} | |
} | |
}; | |
let blockTargetElements = [ | |
[window, "window"], | |
[document, "document"], | |
[document.querySelector("html"), "<html>"] | |
]; | |
blockTargetElements.forEach( (elm) => { | |
elm[0].addEventListener = fuck(elm[0].addEventListener, elm[1]); | |
}); | |
})(); |
- 迂闊に全部のページで html { overflow: auto; } を仕掛けたために破綻するページがあった(twitterのページ最下部判定が壊れた)のを雑に修正
- bodyにもoverflow指定する ( https://audition0902.jp 対策)
- fuck(); 意味ないのでやめた
0.22
- document にイベント付けてるページ対策でクロージャっぽくした(ex. https://keprate.com/web/javascript/mouse-wheel-smooth/ , https://keprate.com/sample/js-mouse-wheel-smooth/index.html?link=true )
0.221 document.addEventListener('load') が通らないことがある
0.23
- html要素にイベント付けてるページ(ex. https://www.miyoshifactory.co.jp/sample/14/index.php )が万一存在したときのために追加しておく
- ブロック対象定義とブロック処理を分岐
- 特に理由はないが var を let に置き換え
0.24
- downloadURL, updateURLが常に古いバージョンを参照していて自動更新できなかった
- support.google.com でコンテンツが消失するため除外
0.25
- amazon(特にread.amazon.co.jpの電書リーダー)で不要なスクロールバーが出るので除外
- twitterが時々わけわからんので除外
0.26(報告ありがとうございます)
- DOMContentLoadedとloadの間に大量のローディングが挟まる場合、overflow: hidden; の除去が遅くなりスクロールできない時間が発生する(ex. http://www.green-arrow.jp/ )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
動機 https://eps-r.hatenablog.com/entry/2016/12/23/wheel-scroll