Skip to content

Commit 27d37f5

Browse files
committed
add pip support for douyu, huya and huomao
0 parents  commit 27d37f5

10 files changed

+128
-0
lines changed

background.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
'use strict';
6+
const paths = ['douyu.com', 'huya.com', 'huomao.com'];
7+
const genConditions = (list) => {
8+
return list.map((word) => {
9+
return new chrome.declarativeContent.PageStateMatcher({
10+
pageUrl: {hostContains: word},
11+
})
12+
});
13+
}
14+
chrome.runtime.onInstalled.addListener(function() {
15+
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
16+
chrome.declarativeContent.onPageChanged.addRules([{
17+
conditions: genConditions(paths),
18+
actions: [new chrome.declarativeContent.ShowPageAction()]
19+
}]);
20+
});
21+
});

images/get_started128.png

2.75 KB
Loading

images/get_started16.png

495 Bytes
Loading

images/get_started32.png

814 Bytes
Loading

images/get_started48.png

1.2 KB
Loading

manifest.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "Getting Started Example",
3+
"version": "1.0",
4+
"description": "Build an Extension!",
5+
"permissions": ["activeTab", "declarativeContent", "storage"],
6+
"options_page": "options.html",
7+
"background": {
8+
"scripts": ["background.js"],
9+
"persistent": false
10+
},
11+
"page_action": {
12+
"default_popup": "popup.html",
13+
"default_icon": {
14+
"16": "images/get_started16.png",
15+
"32": "images/get_started32.png",
16+
"48": "images/get_started48.png",
17+
"128": "images/get_started128.png"
18+
}
19+
},
20+
"icons": {
21+
"16": "images/get_started16.png",
22+
"32": "images/get_started32.png",
23+
"48": "images/get_started48.png",
24+
"128": "images/get_started128.png"
25+
},
26+
"manifest_version": 2
27+
}

options.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
button {
6+
height: 30px;
7+
width: 30px;
8+
outline: none;
9+
margin: 10px;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<div id="buttonDiv">
15+
</div>
16+
<div>
17+
<p>Choose a different background color!</p>
18+
</div>
19+
</body>
20+
<script src="options.js"></script>
21+
</html>

options.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
'use strict';
6+
7+
let page = document.getElementById('buttonDiv');
8+
const kButtonColors = ['#3aa757', '#e8453c', '#f9bb2d', '#4688f1'];
9+
function constructOptions(kButtonColors) {
10+
for (let item of kButtonColors) {
11+
let button = document.createElement('button');
12+
button.style.backgroundColor = item;
13+
button.addEventListener('click', function() {
14+
chrome.storage.sync.set({color: item}, function() {
15+
console.log('color is ' + item);
16+
})
17+
});
18+
page.appendChild(button);
19+
}
20+
}
21+
constructOptions(kButtonColors);

popup.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
button {
6+
height: 30px;
7+
width: 30px;
8+
outline: none;
9+
}
10+
</style>
11+
</head>
12+
<body>
13+
<button id="submitPipRequest">使用悬浮播放器</button>
14+
<script src="popup.js"></script>
15+
</body>
16+
</html>

popup.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
'use strict';
6+
7+
const script = `let id;
8+
const orgin = document.location.origin;
9+
if (origin.includes('douyu')) id = '__video';
10+
if (origin.includes('huya')) id = 'huya_video';
11+
if (origin.includes('huomao')) id = 'live-video';
12+
console.log(id);
13+
document.getElementById(id).requestPictureInPicture();
14+
document.getElementById(id).play();`;
15+
16+
submitPipRequest.onclick = function(element) {
17+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
18+
chrome.tabs.executeScript(
19+
tabs[0].id,
20+
{code: script});
21+
});
22+
};

0 commit comments

Comments
 (0)