Skip to content

Instantly share code, notes, and snippets.

@ArvinH
Last active January 13, 2018 13:56
Show Gist options
  • Save ArvinH/96fa770dcd007c02a69f31676020cbe6 to your computer and use it in GitHub Desktop.
Save ArvinH/96fa770dcd007c02a69f31676020cbe6 to your computer and use it in GitHub Desktop.
chrome.runtime.onMessage.addListener(gotMessage)
function gotMessage(message, sender, sendResponse){
let direction = 0;
if(message.direction == 'up'){
direction = -500;
} else if(message.direction == 'down'){
direction = +500;
} else if (message.direction == 'turn off') {
const mask = document.getElementById('body-maskDiv');
if (mask) {
removeMask();
} else {
addMask();
}
}
window.scrollBy({
top: direction,
left: 0,
behavior: 'smooth'
});
}
function addMask() {
var maskDiv = document.createElement("div");
maskDiv.id = 'body-maskDiv';
maskDiv.setAttribute('style', 'background:rgba(0,0,0,0.6);position:fixed;top:0;width:100%;height:100%;z-index:999');
var playerContainer = document.getElementById('player-container');
playerContainer && (playerContainer.style.zIndex = '1001');
document.body.appendChild(maskDiv);
}
function removeMask() {
document.getElementById('body-maskDiv').remove();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment