Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Clovis1444 committed Aug 13, 2024
0 parents commit 8f7e647
Show file tree
Hide file tree
Showing 9 changed files with 926 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/web-ext-artifacts
/build
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# About

**KPFB** - browser extension that adds a button to any [kinopoisk](https://www.kinopoisk.ru) film page. When the button was clicked it will open [flicksbar's](https://www.flicksbar.mom/) page for corresponding film.

![](images/KPFB.png)

# Deprecated versions

- [KPFB for firefox](https://github.com/Clovis1444/KPFB-firefox)
- [KPFB for chrome](https://github.com/Clovis1444/KPFB-chrome)
Binary file added icons/kpfb-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions icons/kpfb-48.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/KPFB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"manifest_version": 2,
"name": "KPFB",
"version": "0.0.4",
"description": "Quick redirrect to Flickbar from Kinopoisk.",
"browser_specific_settings": {
"gecko": {
"id": "KPFB@CLVS"
}
},
"icons": {
"48": "icons/kpfb-48.png"
},
"permissions": [
"tabs"
],
"background": {
"scripts": [
"src/openFb.js"
]
},
"content_scripts": [
{
"matches": [
"*://*.kinopoisk.ru/film/*",
"*://*.kinopoisk.ru/series/*"
],
"js": [
"src/kpfb.js"
]
}
],
"web_accessible_resources": [
"icons/kpfb-48.png"
]
}
86 changes: 86 additions & 0 deletions src/kpfb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
if (typeof browser === "undefined") {
var browser = chrome;
}

class Kpfb {
static #FB_URL = "https://flicksbar.mom";
static #PARENT1() {
return document.querySelector(
"html > body > div > div > div:nth-of-type(2) > main > div > div:nth-of-type(2) > div > div:nth-of-type(3) > div > div > div > div > div > div:nth-of-type(2) > div:nth-of-type(2) > div"
);
}
static #PARENT2() {
return document.querySelector(
"html > body > div > div > div:nth-of-type(2) > main > div > div:nth-of-type(2) > div > div:nth-of-type(3) > div > div > div > div > div > div:nth-of-type(2) > div"
);
}
static #PARENT3() {
return document.querySelector(
"html > body > div > div > div:nth-of-type(2) > div:nth-of-type(2) > div:nth-of-type(2) > div > div:nth-of-type(3) > div > div > div > div > div > div:nth-of-type(2) > div"
);
}

static #BUTTON_ONCLICK() {
try {
const kpUrl = window.location.href;

browser.runtime.sendMessage({
command: "openFb",
url: Kpfb.getFbLink(kpUrl),
});
} catch (e) {
console.error(e);
}
}

static #getFilmId(url) {
let film = url.pathname.toString();

if (!film) {
throw "Error(KPFB): Failed to find film id";
}

return film;
}

static #createFbLink(film) {
return this.#FB_URL + film;
}

// Must handle exceptions when calling this methode
static getFbLink(kpUrl) {
try {
kpUrl = new URL(kpUrl);
const film = this.#getFilmId(kpUrl);

return this.#createFbLink(film);
} catch (e) {
throw e;
}
}

static createButton() {
// Button
const kpfb_button = document.createElement("img");
kpfb_button.id = "KPFB";
kpfb_button.style.width = "48px";
kpfb_button.style.height = "48px";
kpfb_button.style.paddingRight = "10px";
kpfb_button.title = "Watch on Flicksbar";

const img = browser.runtime.getURL("icons/kpfb-48.png");
kpfb_button.src = img;

kpfb_button.onclick = this.#BUTTON_ONCLICK;

const parent = this.#PARENT1() ?? this.#PARENT2() ?? this.#PARENT3();
parent.appendChild(kpfb_button);
}
}

function main() {
Kpfb.createButton();
}

// Call main()
main();
27 changes: 27 additions & 0 deletions src/openFb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
if (typeof browser === "undefined") {
var browser = chrome;
}

function openNewTab(url, index) {
browser.tabs.create({
url: url,
index: index,
});
}

function main() {
browser.runtime.onMessage.addListener((message) => {
if (message.command === "openFb") {
browser.tabs.query(
{ active: true, lastFocusedWindow: true },
(tabs) => {
openNewTab(message.url, tabs[0].index + 1);
// use `url` here inside the callback because it's asynchronous!
}
);
}
});
}

// Call main()
main();

0 comments on commit 8f7e647

Please sign in to comment.