-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from craftwar/nightbot
Add NightBot support and improve performance
- Loading branch information
Showing
3 changed files
with
26 additions
and
18 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,40 @@ | ||
function makeSetAudioURL(videoElement, url) { | ||
function setAudioURL() { | ||
if (videoElement.src != url) { | ||
videoElement.pause(); | ||
videoElement.src = url; | ||
videoElement.currentTime = 0; | ||
videoElement.play(); | ||
} | ||
var oldUrl; | ||
var makeSetAudioURL = function(videoElement, url) { | ||
if (oldUrl === undefined) { | ||
oldUrl = videoElement.src; | ||
} | ||
if (videoElement.src != url) { | ||
videoElement.pause(); | ||
videoElement.src = url; | ||
videoElement.currentTime = 0; | ||
videoElement.play(); | ||
} | ||
setAudioURL(); | ||
return setAudioURL; | ||
} | ||
}; | ||
|
||
chrome.runtime.onMessage.addListener( | ||
function (request, sender, sendResponse) { | ||
var url = request.url; | ||
var videoElements = document.getElementsByTagName('video'); | ||
var videoElement = videoElements[0]; | ||
let url = request.url; | ||
let videoElement = document.getElementsByTagName('video')[0]; | ||
videoElement.onloadeddata = makeSetAudioURL(videoElement, url); | ||
if (document.getElementsByClassName('audio_only_div').length == 0) { | ||
var extensionAlert = document.createElement('div'); | ||
let audioOnlyDivs = document.getElementsByClassName('audio_only_div'); | ||
if (audioOnlyDivs.length == 0) { | ||
let extensionAlert = document.createElement('div'); | ||
extensionAlert.className = 'audio_only_div'; | ||
|
||
var alertText = document.createElement('p'); | ||
let alertText = document.createElement('p'); | ||
alertText.className = 'alert_text'; | ||
alertText.innerHTML = 'Youtube Audio Extension is running. It disables the video stream and uses only the audio stream' + | ||
' which saves battery life and bandwidth / data when you just want to listen to just songs. If you want to watch' + | ||
' video also, click on the extension icon and refresh your page.'; | ||
|
||
extensionAlert.appendChild(alertText); | ||
var parent = videoElement.parentNode.parentNode; | ||
let parent = videoElement.parentNode.parentNode; | ||
parent.appendChild(extensionAlert); | ||
} | ||
else if (url == "") { | ||
for(div in audioOnlyDivs) { | ||
div.parentNode.removeChild(div); | ||
} | ||
} | ||
} | ||
); |
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