[Userscript] 10wallpaper downloader

  Bài viết hay nhất1
Tải hình nền từ 10wallpaper.com chỉ với 1-Click. Có thể chọn độ phân giải cố định để tải xuống.

Demo


[Userscript] 10wallpaper downloader 10wall10
Tải hình nền từ 10wallpaper

Cài đặt


Dùng một trong các link sau:

  1. https://greasyfork.org/vi/scripts/19854-10wallpaper-downloader
  2. https://openuserjs.org/scripts/baivong/10wallpaper_downloader
  3. https://github.com/baivong/Userscript/raw/master/10wallpaper_downloader/10wallpaper_downloader.user.js

Mã nguồn


Code:
// ==UserScript==
// @name        10wallpaper downloader
// @namespace    http://baivong.github.io/
// @version      2.1.2
// @description  1-Click download on 10wallpaper. You should select the resolution before downloading.
// @icon        http://i.imgur.com/08zfJez.png
// @author      Zzbaivong
// @oujs:author  baivong
// @license      MIT; https://baivong.mit-license.org/license.txt
// @match        http://10wallpaper.com/*
// @match        http://www.10wallpaper.com/*
// @match        https://10wallpaper.com/*
// @match        https://www.10wallpaper.com/*
// @require      https://unpkg.com/file-saver@1.3.8/FileSaver.min.js
// @require      https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js?v=a834d46
// @noframes
// @connect      self
// @supportURL  https://github.com/lelinhtinh/Userscript/issues
// @run-at      document-idle
// @grant        GM.xmlHttpRequest
// @grant        GM_xmlhttpRequest
// @grant        GM.openInTab
// @grant        GM_openInTab
// ==/UserScript==

(function () {
    'use strict';

    /**
    * Resolution config
    * @type {String} // Eg: 1920x1200, 1366x768, 1280x1024, ...
    */
    var resolution = '';


    // Do not change the code below this line, unless you know how.
    var list = document.querySelectorAll('a[href^="/view/"]'),
        res = location.pathname.match(/\d+x\d+/);
    if (!/\d+x\d+/.test(resolution)) resolution = screen.width + 'x' + screen.height;
    res = !res ? resolution : res[0];

    [].forEach.call(list, function (link) {
        var info = link.querySelector('span'),
            infoContent = info.innerHTML,
            img = link.querySelector('img'),
            imgName;

        if (!img) return;
        img = img.src.replace(/(\/|_)(small|medium)(\/|\.)/g, '$1' + res + '$3');
        imgName = img.replace(/.*\//, '');

        link.addEventListener('click', function (e) {
            e.preventDefault();
            info.innerHTML = 'Downloading...';

            GM.xmlHttpRequest({
                method: 'GET',
                url: img,
                responseType: 'blob',
                onprogress: function (e) {
                    var percent = Math.round((e.loaded / e.total) * 100);
                    info.innerHTML = percent + ' %';
                },
                onload: function (response) {
                    var blob = response.response;

                    info.innerHTML = infoContent;
                    link.setAttribute('href', URL.createObjectURL(blob));
                    link.setAttribute('download', imgName);

                    saveAs(blob, imgName);
                },
                onerror: function (err) {
                    console.error(err);
                }
            });
        });

        link.addEventListener('contextmenu', function (e) {
            e.preventDefault();
            GM.openInTab(img);
        });

        link.setAttribute('title', 'Click to download this image\nRight Click to open in new tab');
    });
})();

Hướng dẫn


Thông thường trang 10wallpaper sẽ tự thiết lập độ phân giải (resolution) tương ứng với thiết bị của bạn. Tuy nhiên, bạn có thể thay đổi bằng cách chỉnh tham số resolution trong mã nguồn, dòng 33.
Nhấn chuột vào ảnh để download.
Nhấn chuột phải để mở ảnh trong cửa sổ mới.
Tags: #userscript #download #photo #10wallpaper
You cannot reply to topics in this forum