LINE theme downloader

Download LINE themes using Tampermonkey

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         LINE theme downloader
// @namespace    http://tampermonkey.net/
// @version      1.8
// @description  Download LINE themes using Tampermonkey
// @author       gochi_AI
// @match        https://store.line.me/themeshop/*/*/*
// @grant        none
// @icon         https://scdn.line-apps.com/n/line_store_sp/img/favicon_20160805.ico
// ==/UserScript==

(function() {
    'use strict';

    function extractThemeId(url) {
        let id = url.split('/')[5].split('?')[0];
        return id;
    }

    function extractVersion() {
        var doc = new DOMParser().parseFromString(document.body.innerHTML, 'text/html');
        var version = doc.evaluate('//div[@class="mdCMN38Img"]/img/@src', doc, null, XPathResult.STRING_TYPE, null).stringValue;
        return version.split("/")[10];
    }

    function downloadTheme(url) {
        var themeId = extractThemeId(url);
        var version = extractVersion();
        const buttonElement = document.querySelector('button[data-widget="LinkButton"]');
        var downloadurl = `https://shop.line-scdn.net/themeshop/v1/products/${themeId.substring(0, 2)}/${themeId.substring(2, 4)}/${themeId.substring(4, 6)}/${themeId}/${version}/ANDROID/theme.zip`;
        if (buttonElement === null) {
  const ulElement = document.querySelector('ul.mdCMN38Item01Ul');
  const divElement = document.createElement('div');
  divElement.classList.add('mdCMN38Item01Sub');
  divElement.innerHTML = `<button type="button" class="MdBtn03 mdBtn03P01" data-widget="LinkButton"  data-event-category="sticker" data-event-label="theme_creators" data-event-action="click_theme_premium_trial_PC">download</button>`;
  ulElement.insertAdjacentElement('afterend', divElement);

    const newLinkButton = divElement.querySelector('button[data-widget="LinkButton"]');
    newLinkButton.addEventListener('click', function() {
window.location.href=`${downloadurl}`
  });

} else {
        buttonElement.dataset.href = downloadurl;
        buttonElement.textContent = "download";
        }}
    extractThemeId(window.location.href)
    downloadTheme(window.location.href)
})();