This commit is contained in:
Gregory Tertyshny 2024-07-15 20:52:41 +03:00
parent 3f1fcac663
commit fec251aea9
13 changed files with 41 additions and 11 deletions

1
.gitignore vendored
View file

@ -1,5 +1,4 @@
node_modules
dist
.vscode
web-ext-artifacts
.amo-upload-uuid

2
dist/koboprice.js vendored Normal file

File diff suppressed because one or more lines are too long

7
dist/koboprice.js.map vendored Normal file

File diff suppressed because one or more lines are too long

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

BIN
icons/16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
icons/32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
icons/48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -1,5 +1,5 @@
import { bookUrl } from "./bookUrl";
import { extractPriceFrom } from "./extractPriceFrom";
import { extractPrice } from "./extractPrice";
import { getRate } from "./rates";
import { convertPrice } from "./convertPrice";
import { cacheBookPrice, getBookPrice } from "./cache";
@ -17,7 +17,7 @@ export const bookPriceFor = async (country) => {
return fromCache;
}
const countryPrice = await extractPriceFrom(url);
const countryPrice = await extractPrice(url);
let convertedPrice;

View file

@ -1,6 +1,9 @@
export const bookUrl = (country) => {
const urlPattern = /^https:\/\/www\.kobo\.com\/../;
const newPath = `https://www.kobo.com/${country}`;
const url = window.location.href.replace(urlPattern, newPath);
return window.location.href.replace(urlPattern, newPath);
l("url for country", country, url);
return url;
};

View file

@ -5,9 +5,9 @@ const observePriceOnPage = (page) =>
timeout(10000).then(() => rej("price not found"));
var observer = new MutationObserver(() => {
const price = page.querySelector(
const price = page?.querySelector(
".primary-right-container .pricing-details .active-price span",
).textContent;
)?.textContent;
if (price) {
l("found price", price);
@ -24,7 +24,7 @@ const observePriceOnPage = (page) =>
});
});
export const extractPriceFrom = async (url) => {
export const extractPrice = async (url) => {
try {
l("going to", url);

View file

@ -1,12 +1,12 @@
{
"name": "Kobo Price",
"description": "Find lowest book price on kobo.com",
"version": "1.1.1",
"version": "1.1.4",
"manifest_version": 3,
"permissions": ["activeTab"],
"content_scripts": [
{
"js": ["dist/index.js"],
"js": ["dist/koboprice.js"],
"run_at": "document_end",
"matches": [
"https://www.kobo.com/*/*/ebook/*",
@ -18,5 +18,12 @@
"gecko": {
"id": "koboprice@tertyshny.dev"
}
},
"icons": {
"16": "icons/16.png",
"32": "icons/32.png",
"48": "icons/48.png",
"128": "icons/128.png"
}
}

View file

@ -7,10 +7,11 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint --fix",
"build": "esbuild lib/index.js --bundle --minify --sourcemap --target=chrome58,firefox57,safari11 --outfile=dist/index.js",
"build": "esbuild lib/index.js --bundle --minify --sourcemap --target=chrome58,firefox57,safari11 --outfile=dist/koboprice.js",
"watch-build": "npm run build -- --watch",
"watch-ext": "web-ext run --start-url kobo.com",
"watch": "concurrently npm:watch-build npm:watch-ext"
"watch": "concurrently npm:watch-build npm:watch-ext",
"ext-build": "web-ext build"
},
"author": "",
"license": "ISC",

View file

@ -0,0 +1,11 @@
// ==UserScript==
// @name Kobo Price
// @description finds lowest book price on kobo.com
// @icon https://github.com/fotonmoton/koboprice/blob/master/icon.png?raw=true
// @namespace https://github.com/fotonmoton
// @run-at document-end
// @noframes
// @match https://www.kobo.com/*/*/ebook/*
// @match https://www.kobo.com/*/*/audiobook/*
// @require ../dist/koboprice.js
// ==/UserScript==