This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,233 additions
and
3 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var ipc = require('electron').ipcRenderer; | ||
|
||
ipc.on('play-control', function(event, command){ | ||
var webView = document.querySelector('webview#gpm-player'); | ||
switch (command) { | ||
case 'rewind': | ||
webView.executeJavaScript("window.history.back()"); | ||
break; | ||
case 'forward': | ||
webView.executeJavaScript("document.querySelector('.ytp-next-button').click()"); | ||
break; | ||
case 'play-pause': | ||
webView.executeJavaScript("document.querySelector('.ytp-play-button').click()"); | ||
break; | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Perlotto</title> | ||
<style> | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
</head> | ||
<body style="overflow: hidden"> | ||
<webview id="gpm-player" src="https://www.youtube.com" style="height:100%;width:100%;position:absolute;" preload="inject.js"></webview> | ||
<script src="./content.js"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
(function() { | ||
|
||
const {ipcRenderer} = require('electron'); | ||
var currentTrack = {}; | ||
var updateTimer; | ||
|
||
function scheduleScobbleUpdate(info) { | ||
clearTimeout(updateTimer); | ||
|
||
info.timestamp = Math.floor((+new Date()) / 1000); | ||
updateTimer = setTimeout(function() { | ||
ipcRenderer.send('player-scrobble-time', info) | ||
}, 61000); // a bit bigger then minimal limit | ||
} | ||
|
||
function runWhenLoaded(func) { | ||
if (playerLoadedp()) { | ||
func(); | ||
return; | ||
} | ||
|
||
var timer = setInterval(function() { | ||
if (playerLoadedp()) { | ||
clearInterval(timer); | ||
func(); | ||
return; | ||
} | ||
}, 200); | ||
} | ||
|
||
function runWhenTrackInfoChanges(func) { | ||
var target = document.querySelector('#page'); | ||
target.focus(); | ||
|
||
var observer = new MutationObserver(() => func()); | ||
|
||
var config = { | ||
childList: true, | ||
subtree: true // see crbug.com/134322 | ||
}; | ||
|
||
observer.observe(target, config); | ||
} | ||
|
||
function isPlaying() { | ||
var el = document.querySelector(".html5-main-video"); | ||
return el && !el.paused; | ||
} | ||
|
||
function playerLoadedp() { | ||
return location.href.match(/\/watch\?v=/) && !!document.querySelector(".watch-title"); | ||
} | ||
|
||
function trackInfo() { | ||
var title = document.querySelector('.watch-title').title; | ||
var parts = title.match(/((?:\w+\s+)+)\W+(.*)/); | ||
if (parts && parts.length === 3) { | ||
//best guess | ||
return { | ||
track: parts[2].trim(), | ||
artist: parts[1].trim() | ||
}; | ||
} else { | ||
return { | ||
track: title, | ||
artist: "unknown" | ||
}; | ||
} | ||
} | ||
|
||
function tracksEqualp(one, two) { | ||
return one.track === two.track | ||
&& one.album === two.album | ||
&& one.artist === two.artist; | ||
} | ||
|
||
function analyzeTrackChange() { | ||
var playing = isPlaying(); | ||
if (!playing) return; | ||
|
||
var info = trackInfo(); | ||
|
||
if (!tracksEqualp(currentTrack, info)) { | ||
currentTrack = info; | ||
scheduleScobbleUpdate(info); | ||
ipcRenderer.send('player-song-change', info) | ||
} | ||
} | ||
|
||
runWhenLoaded(runWhenTrackInfoChanges.bind(null, analyzeTrackChange)); | ||
}()); |
Oops, something went wrong.