你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式
你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式
你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式
你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式
你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式
你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式
(我已經安裝了使用者樣式管理器,讓我安裝!)
// ==UserScript==
// @name wap.faloo.com Auto download image
// @namespace http://tampermonkey.net/
// @version 0.7
// @description Tự động lưu image vip trên bfaloo.com
// @author mkbyme
// @match https://wap.faloo.com/chapter/**.html
// @grant GM_download
// @grant GM_getResourceText
// @grant GM_addStyle
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js
// @require https://code.jquery.com/jquery-3.5.1.slim.min.js
// @resource bootstrap5Css https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css
// ==/UserScript==
var bootstrap5Css = GM_getResourceText("bootstrap5Css");
GM_addStyle(bootstrap5Css);
(function () {
'use strict';
let uiTemplate = `
<style>
.mk-wrap {
position: fixed;
top: 0;
right: 0;
background-color: #4caf50;
}
</style>
<div class="mk-wrap main-view p-3 rounded-3 shadow-sm">
<h3>Auto download image bfaloo.com by @<a href="https://m.me/mkbyme" target="_blank">mkbyme</a></h3>
<div class="mk-body">
<h5>Thiết lập cấu hình tải xuống</h5>
<div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Thời gian chờ load ảnh xong(s)</span>
<input type="number" value="15" class="form-control mk-txt-loadimage" aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Thời gian mở chương mới(s)</span>
<input type="number" value="30" class="form-control mk-txt-timer" aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Tiền tố lưu tệp ảnh</span>
<input type="text" value="" placeholder="Ví dụ: tên truyện" class="form-control mk-txt-prefix"
aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">CSS Selector ảnh VIP</span>
<input type="text" value="#content img[id^=vip]" placeholder="CSS Selector để chọn ra các ảnh VIP"
class="form-control mk-txt-css-selector" aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-sm">
</div>
<div class="form-check">
<input class="form-check-input mk-chk-save-with-chapter-name" checked type="checkbox"
id="chkExtChapterName">
<label class="form-check-label" for="chkExtChapterName">
Tên ảnh kèm tên của chapter
</label>
</div>
<div class="mk-status"></div>
</div>
</div>
<div class="mk-footer d-flex justify-content-between">
<div class="d-flex">
<button class="btn btn-success mk-btn-save-config">Lưu lại</button>
<button class="btn btn-light mk-btn-download">Bắt đầu tải</button>
</div>
<div class="">
<button class="btn btn-light mk-btn-pause">Tạm dừng</button>
<button class="btn btn-light mk-btn-collapse">Thu nhỏ</button>
</div>
</div>
</div>
<div class="mk-wrap hidden-view p-3 rounded-3 shadow-sm d-none">
<button class="btn btn-light mk-btn-expanse">Mở rộng</button>
</div>
`;
var div = document.createElement("div");
var $ = window.jQuery;
div.innerHTML = uiTemplate;
document.body.appendChild(div);
var key = {
LoadImageDelay: "load_image_delay",
Timer: "timer",
Prefix: "prefix",
HasNextChatper: "next_chapter",
CssSelectorImages: "css_selector_img",
DownloadStatus: "download_status",
ExtIncludeChapterName: "ext_inc_chapter_name"
};
//common function
var hanlderStatus = null;
var downloadStatus = 1;
var fnUpdateStatus = function (text) {
$(".mk-wrap .mk-status").text(text);
console.log(text);
if (hanlderStatus) {
clearTimeout(hanlderStatus);
}
//xóa text sau 3s
hanlderStatus = setTimeout(() => {
$(".mk-wrap .mk-status").text("");
}, 3000);
}
var fnSetConfig = function (name, value) {
window.localStorage.setItem(`mkconfig_${name}`, value);
}
var fnGetConfig = function (name, defaulValue = 0, type = 1) {
let ret = defaulValue;
if (window.localStorage) {
ret = window.localStorage.getItem(`mkconfig_${name}`);
if (ret) {
if (type == 1 && /^\d+$/.test(ret)) {
//number
ret = parseInt(ret);
}
else if (type == 2) {
//boolean
if (ret.toLowerCase() == "true") {
ret = true;
}
else {
ret = false;
}
}
}
}
return ret ? ret : defaulValue;
}
var fnGetNumberValue = function (selector, defaultValue = 15) {
if (!defaultValue) {
defaultValue = 0;
}
var ret = defaultValue;
let val = $(selector).val();
if (val && /^\d+$/.test(val)) {
ret = parseInt(val);
}
return ret;
}
var fnInit = function () {
var hasNextChatper = fnGetConfig(key.HasNextChatper, 0);
downloadStatus = fnGetConfig(key.DownloadStatus, 0);
$('.mk-wrap .mk-txt-loadimage').val(fnGetConfig(key.LoadImageDelay, 15));
$('.mk-wrap .mk-txt-timer').val(fnGetConfig(key.Timer, 30));
$('.mk-wrap .mk-txt-prefix').val(fnGetConfig(key.Prefix, "", 0));
$('.mk-wrap .mk-txt-css-selector').val(fnGetConfig(key.CssSelectorImages, "#content img[id^=vip]", 0));
$('.mk-wrap .mk-chk-save-with-chapter-name').prop('checked', fnGetConfig(key.ExtIncludeChapterName, 0) ? true : false);
if (downloadStatus) {
$(".mk-wrap .mk-btn-pause").text("Tạm ngừng");
}
else {
$(".mk-wrap .mk-btn-pause").text("Tiếp tục");
}
if (hasNextChatper) {
var timerDelay = fnGetNumberValue('.mk-wrap .mk-txt-loadimage', 15);
var timerDelayCount = timerDelay;
var logImageHandler = setInterval(() => {
if (downloadStatus) {
if (timerDelayCount > 0) {
timerDelayCount--;
fnUpdateStatus(`Đang chờ tải ảnh xong....${timerDelayCount}(s)`);
}
else {
clearInterval(logImageHandler);
fnDownload();
}
}
else {
fnUpdateStatus(`Đã tạm dừng`);
}
}, 1000);
}
}
var fnDownload = function () {
fnUpdateStatus(`Bắt đầu tải xuống`);
let prefix = $(".mk-wrap .mk-txt-prefix").val();
var chapterId = /(\d+).html$/.exec(window.location.href);
if (chapterId) {
if (chapterId.length > 1) {
chapterId = chapterId[1];
} else if (chapterId.length) {
chapterId = chapterId[0];
} else {
chapterId = "";
}
} else {
chapterId = "";
}
var imgs = $($('.mk-wrap .mk-txt-css-selector').val());
if (imgs.length > 0) {
let incChapterName = $('.mk-wrap .mk-chk-save-with-chapter-name').prop('checked');
for (var i = 0; i < imgs.length; i++) {
let downloadArgs = {
url: imgs[i].src,
name: `${prefix}${(incChapterName ? $("#p_name h1").text() : "")}${chapterId}_${(i + 1)}.gif`
}
GM_download(downloadArgs);
fnUpdateStatus(`Đã tải xuống ${imgs[i].src}`);
}
}
else {
fnUpdateStatus("Không có ảnh để tải xuống");
}
//mở link chương tiếp theo
var nextChapterLink = $("#page_1 a:nth-child(2)");
//gắn flag có chương tiếp theo
fnSetConfig(key.HasNextChatper, nextChapterLink.length > 0 ? 1 : 0);
if (nextChapterLink.length > 0) {
var countDownTimeConfig = $(".mk-wrap .mk-txt-timer").val();
var countDownValue = 30;
if (countDownTimeConfig && /^\d+$/.test(countDownTimeConfig)) {
countDownValue = parseInt(countDownTimeConfig);
}
var countDownTemp = countDownValue;
var nextChapterHandle = setInterval(() => {
if (downloadStatus) {
if (countDownTemp > 0) {
fnUpdateStatus(`Chuyển sang trang tiếp sau sau ${countDownTemp}(s)`);
countDownTemp--;
}
else {
fnUpdateStatus(`Chuyển sang chương tiếp theo và chờ tải xuống...`);
clearInterval(nextChapterHandle);
nextChapterLink[0].click();
}
}
else {
fnUpdateStatus(`Đã tạm dừng`);
}
}, 1000);
} else {
fnUpdateStatus("Đã tải hết");
alert("Đã tải hết chương");
}
};
//event
//xử lý ẩn hiện panel
var collapse = false;
$(".mk-wrap .mk-btn-collapse").off("click").on("click", function (e) {
$(".mk-wrap.main-view").addClass("d-none");
$(".mk-wrap.hidden-view").removeClass("d-none");
collapse = true;
});
$(".mk-wrap .mk-btn-expanse").off("click").on("click", function (e) {
$(".mk-wrap.main-view").removeClass("d-none");
$(".mk-wrap.hidden-view").addClass("d-none");
collapse = false;
});
$(".mk-wrap .mk-btn-pause").off("click").on("click", function (e) {
if (downloadStatus) {
$(".mk-wrap .mk-btn-pause").text("Tiếp tục");
fnUpdateStatus("Đã tạm ngừng");
}
else {
$(".mk-wrap .mk-btn-pause").text("Tạm ngừng");
fnUpdateStatus("Tiếp tục tải");
}
downloadStatus = !downloadStatus;
fnSetConfig(key.DownloadStatus, downloadStatus ? 1 : 0);
});
//lưu thiết lập
$(".mk-wrap .mk-btn-save-config").off("click").on("click", function (e) {
let timer = fnGetNumberValue('.mk-wrap .mk-txt-loadimage', 15);
let timerCount = fnGetNumberValue('.mk-wrap .mk-txt-timer', 15);
let prefix = $('.mk-wrap .mk-txt-prefix').val();
let cssSelector = $('.mk-wrap .mk-txt-css-selector').val();
fnSetConfig(key.LoadImageDelay, timer);
fnSetConfig(key.Timer, timerCount);
fnSetConfig(key.Prefix, prefix);
fnSetConfig(key.CssSelectorImages, cssSelector);
fnSetConfig(key.DownloadStatus, downloadStatus);
fnUpdateStatus("Đã lưu thiết lập");
});
//tải xuống
$(".mk-wrap .mk-btn-download").off("click").on("click", function (e) {
fnDownload();
if (!downloadStatus) {
$(".mk-wrap .mk-btn-pause").click();
}
});
//checkbox
$('.mk-wrap .mk-chk-save-with-chapter-name').off('click').on('click', function (e) {
let checked = $('.mk-wrap .mk-chk-save-with-chapter-name').prop('checked');
fnSetConfig(key.ExtIncludeChapterName, checked ? 1 : 0);
});
//run
fnInit();
})();