Created
May 23, 2024 12:58
-
-
Save iigmir/3d55e44820cb830add95cef0d29ed463 to your computer and use it in GitHub Desktop.
Return the total price of your wishlist on DLsite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Total prices | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-05-19 | |
// @description Return the total price of your wishlist before yuo try to clean. | |
// @author You | |
// @match https://www.dlsite.com/**/mypage/wishlist | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=dlsite.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
"use strict"; | |
// Your code here... | |
console.log("TP: Total prices"); | |
const get_prices = () => { | |
const dom = document.querySelectorAll(".work_1col_table .work_price"); | |
const callback = (i = "") => i.textContent.replace(/[^0-9.]/g, ""); | |
return [...dom].map( callback ); | |
}; | |
const get_total_price = (input = [""]) => { | |
return input | |
.map( t => parseInt(t,10) ) | |
.reduce( (x,y) => x + y ) | |
; | |
}; | |
const result = get_total_price( get_prices() ); | |
const render_to_page_total = (input = 0) => { | |
// span | |
const hint = document.createElement("i"); | |
hint.textContent = ` 総額:${String(input)} 円`; | |
hint.classList.add("work_price"); | |
// render | |
console.log({ total_price: result }); | |
document.querySelector(".page_total").appendChild(hint); | |
}; | |
render_to_page_total(result); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment