refactor code. create getController

This commit is contained in:
Jonathan Dawson
2020-01-03 12:33:04 -06:00
parent 2c3cd57dc5
commit aa055a5e8f

View File

@@ -180,9 +180,7 @@
var observer=new MutationObserver((mutations) => { var observer=new MutationObserver((mutations) => {
mutations.forEach((mutation) => { mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && (mutation.attributeName === 'src' || mutation.attributeName === 'currentSrc')){ if (mutation.type === 'attributes' && (mutation.attributeName === 'src' || mutation.attributeName === 'currentSrc')){
var controller = getShadow(document.body).filter(x => { var controller = getController(this.id)
return x.attributes['data-vscid'] && x.tagName == 'DIV' && x.attributes['data-vscid'].value==`${this.id}`
})[0]
if(!controller){ if(!controller){
return; return;
} }
@@ -356,6 +354,13 @@
getChild(parent) getChild(parent)
return result return result
} }
function getController(id){
return getShadow(document.body).filter(x => {
return x.attributes['data-vscid'] &&
x.tagName == 'DIV' &&
x.attributes['data-vscid'].value==`${id}`
})[0]
}
function initializeNow(document) { function initializeNow(document) {
if (!tc.settings.enabled) return; if (!tc.settings.enabled) return;
@@ -518,9 +523,7 @@
mediaTags.forEach(function(v) { mediaTags.forEach(function(v) {
var id = v.dataset['vscid']; var id = v.dataset['vscid'];
var controller = getShadow(document.body).filter(x => { var controller = getController(id)
return x.attributes['data-vscid'] && x.tagName == 'DIV' && x.attributes['data-vscid'].value==`${id}`
})[0]
// Don't change video speed if the video has a different controller // Don't change video speed if the video has a different controller
if (e && !(targetController == controller)) { if (e && !(targetController == controller)) {
return; return;