Skip to content

Instantly share code, notes, and snippets.

@epser
Last active June 24, 2020 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epser/435a6bc6271fa63a467c1f1e3851a04d to your computer and use it in GitHub Desktop.
Save epser/435a6bc6271fa63a467c1f1e3851a04d to your computer and use it in GitHub Desktop.
Webページのホイール操作が勝手にスムーススクロール(余韻スクロール)になるのを止めるUserScript(TamperMonkey)
// ==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]);
});
})();
@epser
Copy link
Author

epser commented Aug 30, 2018

@epser
Copy link
Author

epser commented Sep 5, 2018

https://gist.github.com/epser/435a6bc6271fa63a467c1f1e3851a04d/revisions#diff-6e93016e5d8c13006831446452544de7

  • 迂闊に全部のページで html { overflow: auto; } を仕掛けたために破綻するページがあった(twitterのページ最下部判定が壊れた)のを雑に修正
  • bodyにもoverflow指定する ( https://audition0902.jp 対策)
  • fuck(); 意味ないのでやめた

@epser
Copy link
Author

epser commented Sep 27, 2018

0.22

@epser
Copy link
Author

epser commented Sep 27, 2018

0.221 document.addEventListener('load') が通らないことがある

@epser
Copy link
Author

epser commented Apr 18, 2019

0.23

  • html要素にイベント付けてるページ(ex. https://www.miyoshifactory.co.jp/sample/14/index.php )が万一存在したときのために追加しておく
  • ブロック対象定義とブロック処理を分岐
  • 特に理由はないが var を let に置き換え

@epser
Copy link
Author

epser commented Jun 10, 2019

0.24

  • downloadURL, updateURLが常に古いバージョンを参照していて自動更新できなかった
  • support.google.com でコンテンツが消失するため除外

@epser
Copy link
Author

epser commented Jun 23, 2020

0.25

  • amazon(特にread.amazon.co.jpの電書リーダー)で不要なスクロールバーが出るので除外
  • twitterが時々わけわからんので除外

@epser
Copy link
Author

epser commented Jun 24, 2020

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