Last active
June 10, 2019 16:29
-
-
Save Phate334/860751ddee158419220a10238330b53c to your computer and use it in GitHub Desktop.
在 Facebook Creator Studio 音樂庫中自動切換下一首歌曲。https://www.facebook.com/creatorstudio/
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
// Auto switch to next one when end of a song. | |
// start playing a song then paste this code. | |
(function() { | |
function getElementByXpath(path) { | |
return document.evaluate( | |
path, | |
document, | |
null, | |
XPathResult.FIRST_ORDERED_NODE_TYPE, | |
null | |
).singleNodeValue; | |
} | |
var timecodeNow = | |
"/html/body/div[1]/div/div[2]/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div[4]/div/div[2]/div/div[2]/div[1]"; | |
var timecodeEnd = | |
"/html/body/div[1]/div/div[2]/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div[4]/div/div[2]/div/div[2]/div[3]"; | |
var nextSong = | |
"/html/body/div[1]/div/div[2]/div/div/div[2]/div[1]/div[2]/div[2]/div/div[4]/div/div[2]/div/div[1]/a[5]"; | |
var eleNow = getElementByXpath(timecodeNow); | |
var eleEnd = getElementByXpath(timecodeEnd); | |
var eleNext = getElementByXpath(nextSong); | |
// https://codepen.io/webgeeker/pen/YjrZgg | |
const MutationObserver = | |
window.MutationObserver || | |
window.WebKitMutationObserver || | |
window.MozMutationObserver; | |
const config = { | |
attributes: true, | |
childList: true, | |
characterData: true, | |
subtree: true | |
}; | |
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.type === "characterData") { | |
if ( | |
eleNow.innerText === eleEnd.innerText && | |
eleEnd.innerText !== "0:00" | |
) { | |
eleNext.click(); | |
} | |
} | |
}); | |
}); | |
observer.observe(eleNow, config); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment