Skip to content

Commit f09b729

Browse files
committed
banner injection script added to extension
1 parent f367277 commit f09b729

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

extension.crx

-222 Bytes
Binary file not shown.

extension/background.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@ chrome.action.onClicked.addListener(tab => {
33
target: {tabId: tab.id},
44
files: ['main.js'],
55
}, () => chrome.runtime.lastError); // ignoring the error
6-
});
6+
});
7+
8+
/* currently not working
9+
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
10+
if (changeInfo.status == 'complete') {
11+
chrome.scripting.executeScript({
12+
target: {tabId: tab.id},
13+
files: ['banner.js'],
14+
}, () => chrome.runtime.lastError);
15+
}
16+
}) */

extension/banner.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Get id, type & title of current movie
2+
function getMovieData() {
3+
const url = window.location.href;
4+
const splitted = url.split('/');
5+
const id = splitted[4];
6+
const type = splitted[3];
7+
const title = document.querySelector('meta[property="og:title"]')?.content;
8+
return { id, type, title };
9+
}
10+
11+
// Open page with Yohoho player
12+
function openPlayer(id) {
13+
window.open('https://4h0y.gitlab.io/#' + id, '_blank').focus();
14+
}
15+
16+
// Mount KinoFree banner to the page
17+
function mountBanner(id, title) {
18+
const banner = document.createElement('div');
19+
banner.id = 'kinofree';
20+
banner.style.width = '32px';
21+
banner.style.height = '128px';
22+
banner.style.top = '-128px';
23+
banner.style.left = '8px';
24+
banner.style.outline = 'none';
25+
banner.style.cursor = 'pointer';
26+
banner.style.position = 'fixed';
27+
banner.style.zIndex = '9999999999';
28+
banner.style.transition = 'top 0.2s ease';
29+
30+
banner.innerHTML = `
31+
<?xml version="1.0" encoding="utf-8"?>
32+
<svg viewBox="0 0 128 512" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;" xmlns="http://www.w3.org/2000/svg">
33+
<defs>
34+
<linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(128,512,-2048,512,0,0)">
35+
<stop offset="0" style="stop-color:rgb(248,12,101);stop-opacity:1"/>
36+
<stop offset="1" style="stop-color:rgb(247,88,27);stop-opacity:1"/>
37+
</linearGradient>
38+
</defs>
39+
<path id="Banner" d="M128,0L0,0L0,512L64,480L128,512L128,0Z" style="fill:url(#_Linear1);"/>
40+
<path d="M 54.481998443603516 308.0162353515625 L 45.341373443603516 317.8599853515625 L 45.341373443603516 342.2349853515625 L 27.763248443603516 342.2349853515625 L 27.763248443603516 256.9224853515625 L 45.341373443603516 256.9224853515625 L 45.341373443603516 295.5943603515625 L 53.075748443603516 284.9888916015625 L 74.81402969360352 256.9224853515625 L 96.43512344360352 256.9224853515625 L 66.14215469360352 294.8326416015625 L 97.31402969360352 342.2349853515625 L 76.39606094360352 342.2349853515625 Z" transform="matrix(0, -1, 1, 0, -236.234375, 480.140625)" style="fill: rgb(255, 255, 255); white-space: pre;"/>
41+
</svg>
42+
`;
43+
44+
setTimeout(() => {
45+
banner.style.top = '-32px';
46+
banner.addEventListener('click', () => openPlayer(id, title));
47+
banner.addEventListener('mouseover', () => { banner.style.top = '0px' });
48+
banner.addEventListener('mouseout', () => { banner.style.top = '-32px' });
49+
}, 100);
50+
51+
document.body.appendChild(banner);
52+
}
53+
54+
// Initialize script
55+
function init() {
56+
const { id, type, title } = getMovieData();
57+
if (type === 'film' || type === 'series') mountBanner(id, title);
58+
}
59+
60+
var url = window.location.toString()
61+
62+
if (/https:\/\/www\.kinopoisk\.ru\/(film|series)\/(\d{1,9})\/.*/g.test(url)) {
63+
init();
64+
}

extension/manifest.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{
22
"name": "KinoFree",
33
"description": "Бесплатный доступ к фильмам и сериалам КиноПоиска",
4-
"version": "0.1.6",
4+
"version": "0.2.0",
55
"manifest_version": 3,
66
"background": {
77
"service_worker": "background.js"
88
},
9+
"content_scripts": [
10+
{
11+
"matches": [
12+
"<all_urls>"
13+
],
14+
"js": ["banner.js"]
15+
}
16+
],
917
"commands": {
1018
"_execute_action": {
1119
"suggested_key": {

script/kinofree.user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ function getMovieData() {
4040
return { id, type, title };
4141
}
4242

43-
// Open page with Kinopoisk Watch player
43+
// Open page with Yohoho player
4444
function openPlayer(id) {
4545
window.open(kinopoiskWatchLink + id, '_blank').focus();
4646
}
4747

48-
// Mount Kinopoisk Watch banner to the page
48+
// Mount KinoFree banner to the page
4949
function mountBanner(id, title) {
5050
const banner = document.createElement('div');
5151
banner.id = 'kinofree';

0 commit comments

Comments
 (0)