Last active
January 13, 2018 13:56
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
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