WeComics AP Features

Implements various features and fixes for WeComics

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WeComics AP Features
// @namespace    https://greasyfork.org/en/users/689482-quin15
// @version      1.0.8
// @description  Implements various features and fixes for WeComics
// @author       Quin15
// @match        https://m.wecomics.com/comic/index*
// @icon         https://www.google.com/s2/favicons?domain=wecomics.com
// @grant        unsafeWindow
// ==/UserScript==

if (document.body.innerText.indexOf('error_code":1001') > -1) {
    location.href = "https://m.wecomics.com/comic/index/id/" + window.location.search.replace('?id=', '') + window.location.search;
}

fetch("https://m.wecomics.com/h5/comic/detail/id/" + location.search.split('=')[1].split('&')[0] + "?plain=1",
      {"body": null,"method": "GET"
      }).then((response) => {
    response.json().then((data) => {
        data.data.chapter_list.reverse();
        unsafeWindow.data = data;

        var searchAP = document.createElement('div');
        searchAP.style = "float:left;width:100px;height:50px;background:#ff8c75;border-radius:4px;cursor:pointer;box-shadow:rgb(255 140 117 / 60%) 0rem 0.425rem 0.425rem 0rem;margin-top:15px;"
        searchAP.innerHTML = `<img src="https://www.anime-planet.com/favicon.ico" style="float:left;height:30px;margin:10px 0px 0px 10px;"><p style="font-size:14px;text-align:center;padding:11px;color:#fff">Search On AP</p>`;
        document.querySelector('.comic-detail').appendChild(searchAP)
        searchAP.addEventListener("click", function() {open(encodeURI("https://www.anime-planet.com/manga/all?name=" + document.querySelector('.comic-detail .comic-info h2').innerText), "")});

        var coverImg = document.createElement('div');
        coverImg.style = "float:left;width:100px;height:50px;background:#ff8c75;border-radius:4px;cursor:pointer;box-shadow:rgb(255 140 117 / 60%) 0rem 0.425rem 0.425rem 0rem;margin:15px 0px 0px 10px;"
        coverImg.innerHTML = `<img src="` + data.data.comic.cover_v_url + `" style="float:left;height:30px;margin:10px 0px 0px 10px;"><p style="font-size:14px;text-align:center;padding:3px;color:#fff">Open Cover Image</p>`;
        document.querySelector('.comic-detail').appendChild(coverImg)
        coverImg.addEventListener("click", function() {open(data.data.comic.cover_v_url, "")});

        var checkElems = function() {if (document.querySelectorAll('.chapter-box .chapter-list .chapter-item')[16]) {setTimeout(addListeners, 1000)} else {setTimeout(checkElems, 100);}};
        checkElems();
    });
});

var addListeners = function() {
    document.querySelector('.show-num').remove();
    document.querySelector('.comic-detail .comic-info h2').style.userSelect = "text";
    document.querySelector('.comic-detail .comic-info h2').nextElementSibling.style.userSelect = "text";
    document.querySelector('.comic-detail').style = "overflow:hidden;padding-bottom:20px;"
    document.querySelector('.comic-detail .contents p').style = "user-select:text;overflow:visible;text-overflow:unset;-webkit-line-clamp:unset;height:auto;";
    document.querySelector('.chapter a').addEventListener("click", function() {populateTitles()});
    document.querySelectorAll('.chapter a')[1].addEventListener("click", function() {populateTitles()});
    document.querySelectorAll('.chapter-list .chapter-item')[16].addEventListener("click", function() {populateTitles()});

    if (location.href.indexOf('index?id') > -1) {
        window.history.replaceState({}, "", "https://m.wecomics.com/comic/index/id/" + window.location.search.replace('?id=', '') + window.location.search);
    };

    populateTitles();
}

unsafeWindow.populateTitles = function() {
    setTimeout(function() {
        var textNodes = document.querySelectorAll('.chapter-box .chapter-list .chapter-item');
        for (var i = 0; i < textNodes.length; i++) {
            var chapNum = parseInt(textNodes[i].firstElementChild.innerText);
            if (!isNaN(chapNum)) {
                textNodes[i].setAttribute("title", unsafeWindow.data.data.chapter_list[chapNum-1].publish_date + "   " + unsafeWindow.data.data.chapter_list[chapNum-1].title);
            }
        }
    }, 200);
}