Last active
July 29, 2016 05:04
-
-
Save rikuba/d6f3aa679aa5059ff4b7f459d46eb283 to your computer and use it in GitHub Desktop.
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 wheel de slide | |
// @namespace http://rikuba.com/ | |
// @include http://www.slideshare.net/* | |
// @include https://www.slideshare.net/* | |
// @include http://speakerdeck.com/player/* | |
// @include https://speakerdeck.com/player/* | |
// @include http://slides.com/* | |
// @include http://qiita.com/* | |
// @include http://niconare.nicovideo.jp/watch/* | |
// @include http://azu.github.io/slide-pdf.js/* | |
// @version 1.3 | |
// @grant GM_log | |
// ==/UserScript== | |
const siteinfoList = [ | |
// embedded slideshare | |
{ | |
url: /^https?:\/\/www\.slideshare\.net\/slideshow\//, | |
target: '#player', | |
prev: '#btnPrevious', | |
next: '#btnNext', | |
}, | |
{ | |
url: /^https?:\/\/www\.slideshare\.net\/[^/]+\/[^/]+/, | |
target: '#svPlayerId', | |
prev: '#btnPrevious', | |
next: '#btnNext', | |
}, | |
{ | |
url: /^https?:\/\/speakerdeck\.com\/player\//, | |
target: '#player', | |
prev: '.prev', | |
next: '.next', | |
}, | |
{ | |
url: /http:\/\/slides\.com\//, | |
target: '.reveal', | |
prev: '.navigate-left', | |
next: '.navigate-right', | |
}, | |
{ | |
url: /^http:\/\/qiita\.com\/[^/]+/, | |
target: '*[data-react-class="T.SlideContainer"]', | |
prev: '.slide_controller_btnGroup > .slide_controller_btn:first-child', | |
next: '.slide_controller_btnGroup > .slide_controller_btn:last-child', | |
}, | |
{ | |
url: /^http:\/\/niconare\.nicovideo\.jp\/watch\//, | |
target: '#main-box', | |
prev: '#page-previous', | |
next: '#page-next', | |
}, | |
// | |
{ | |
url: /^http:\/\/azu\.github\.io\/slide-pdf\.js\//, | |
target: ':root', | |
prev: '#js-prev', | |
next: '#js-next', | |
}, | |
]; | |
for (let siteinfo of siteinfoList) { | |
if (siteinfo.url.test(location.href)) { | |
const target = document.querySelector(siteinfo.target); | |
if (target) { | |
target.addEventListener('wheel', createWheelHandler(siteinfo)); | |
break; | |
} | |
GM_log('target element not found'); | |
} | |
} | |
function createWheelHandler(siteinfo) { | |
let elements = { | |
prev: null, | |
next: null, | |
}; | |
return function handleWheel(e) { | |
if (e.deltaY < 0) { | |
clickElement(e, 'prev'); | |
} else if (e.deltaY > 0) { | |
clickElement(e, 'next'); | |
} | |
}; | |
function clickElement(e, key) { | |
if (!elements[key]) { | |
elements[key] = e.currentTarget.querySelector(siteinfo[key]); | |
if (!elements[key]) { | |
GM_log(`${key} element not found`); | |
return; | |
} | |
} | |
e.preventDefault(); | |
elements[key].click(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment