Skip to content

Commit

Permalink
支持爱奇艺
Browse files Browse the repository at this point in the history
  • Loading branch information
SSShooter committed Sep 13, 2020
1 parent c0b0ee9 commit 6b9db12
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 5 deletions.
8 changes: 6 additions & 2 deletions syncHime/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"websocketConnectStart": {
"message": "websocket connect start",
"description": "The string we search for. Put %20 between words that go together."
"description": "nope"
},
"save": {
"message": "save",
"description": "The string we search for. Put %20 between words that go together."
"description": "nope"
},
"saving": {
"message": "saving",
"description": "nope"
}
}
8 changes: 6 additions & 2 deletions syncHime/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"websocketConnectStart": {
"message": "websocket 开始连接",
"description": "The string we search for. Put %20 between words that go together."
"description": "nope"
},
"save": {
"message": "保存",
"description": "The string we search for. Put %20 between words that go together."
"description": "nope"
},
"saving": {
"message": "保存中",
"description": "nope"
}
}
14 changes: 13 additions & 1 deletion syncHime/domAppend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", async function () {
let send = chrome.runtime.getURL("icon/send.svg");
let connect = chrome.runtime.getURL("icon/connect.svg");
let disconnect = chrome.runtime.getURL("icon/disconnect.svg");
Expand Down Expand Up @@ -26,5 +26,17 @@ document.addEventListener("DOMContentLoaded", function () {
if (location.href.match("bilibili"))
document.querySelector("#bilibiliPlayer").appendChild(div);
if (location.href.match("youtube")) document.body.appendChild(div);
if (location.href.match("iqiyi")) {
await waitSec(2);
document.querySelector(".iqp-player").appendChild(div);
}
// document.body.appendChild(div)
});

function waitSec(sec) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, sec * 1000);
});
}
3 changes: 3 additions & 0 deletions syncHime/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#connect-window {
box-sizing: content-box !important;
position: fixed;
bottom: 20px;
right: 20px;
Expand All @@ -15,7 +16,9 @@
transition: background-color 1s 0s, height 1s 0s, width 1s 0s, color 1s 0s,
padding 1s 0s, border-color 1s 0s;
}

#connect-window * {
box-sizing: content-box !important;
opacity: 1;
transition: opacity 1s 0.5s;
}
Expand Down
30 changes: 30 additions & 0 deletions syncHime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ document.addEventListener("DOMContentLoaded", async function () {
video = document.querySelector(".bilibili-player-video video");
if (location.href.match("youtube"))
video = document.querySelector(".ytd-player video");
if (location.href.match("iqiyi")) {
await waitSec(2);
video = document.querySelector(".iqp-player video");
}
const messageBox = document.querySelector("#message-box");
const connectWindow = document.querySelector("#connect-window");
const start = document.querySelector("#start-button");
Expand Down Expand Up @@ -352,3 +356,29 @@ function storageGet(key) {
});
});
}

function waitFor(propertyName, value) {
return new Promise((resolve, reject) => {
let observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (!mutation.addedNodes) return;
for (let i = 0; i < mutation.addedNodes.length; i++) {
// do things to your newly added nodes here
let node = mutation.addedNodes[i];
if (node[propertyName] === value) {
resolve();
// stop watching using:
observer.disconnect();
}
}
});
});

observer.observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false,
});
});
}
1 change: 1 addition & 0 deletions syncHime/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"matches": [
"https://www.bilibili.com/video/*",
"https://www.bilibili.com/bangumi/play/*",
"https://www.iqiyi.com/v_*",
"https://www.youtube.com/watch*"
],
"js": [
Expand Down
1 change: 1 addition & 0 deletions syncHime/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const url = document.querySelector("#websocket-url");
const type = document.querySelector("#connection-type");

const save = document.querySelector("#save");
save.innerText = chrome.i18n.getMessage("save");

chrome.storage.sync.get(["websocket", "connectionType"], function (result) {
url.value = result.websocket || "synchime.herokuapp.com";
Expand Down

0 comments on commit 6b9db12

Please sign in to comment.