Skip to content

Instantly share code, notes, and snippets.

@dandelionred
Last active September 2, 2020 12:20
Show Gist options
  • Select an option

  • Save dandelionred/8c6059be4b2fdc55bb990baea8298a67 to your computer and use it in GitHub Desktop.

Select an option

Save dandelionred/8c6059be4b2fdc55bb990baea8298a67 to your computer and use it in GitHub Desktop.

Revisions

  1. dandelionred revised this gist Sep 2, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.8
    // @version 0.8.1
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    @@ -79,7 +79,7 @@
    downButton.appendChild(a);
    }

    downButton.firstChild.href = "http://download-link.lan:81/convert.php?url=" + base64X(img.src);
    downButton.firstChild.href = "http://local.download1.net:81/convert.php?url=" + base64X(img.src);
    }

    setInterval(main, 500);
  2. dandelionred revised this gist Feb 22, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.8
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    // ==/UserScript==

  3. dandelionred revised this gist Feb 22, 2020. 1 changed file with 47 additions and 44 deletions.
    91 changes: 47 additions & 44 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,16 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.7
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @version 0.8
    // @match https://m.vk.com/*
    // ==/UserScript==

    (function() {
    'use strict';
    (function () {
    'use strict';

    var location = null;
    let location = null;

    var html = `
    const html = `
    <style>
    #down-button {
    position: absolute;
    @@ -33,49 +31,54 @@
    <div id="down-button"></div>
    `;

    function log( s) {
    console.log("["+(new Date()).getTime()+"] " + s);
    }
    function log(s) {
    console.log("[" + (new Date()).getTime() + "] " + s);
    }

    function evClick( ev) {
    // ev.preventDefault();
    // log("click");
    // return false;
    }
    /**
    * Convert unicode string to utf-8, base64 encode, replace "+/=" with "._-".
    * @param {String} s
    * @returns {String}
    */
    function base64X(s) {
    const pairs = {
    "+": ".",
    "/": "_",
    "=": "-"
    };

    function main() {
    var z_photoview = document.getElementById("z_photoview");
    if (!z_photoview) {
    location = null;
    return;
    }
    return window.btoa(unescape(encodeURIComponent(s))).replace(/[+/=]/g, m => pairs[m]);
    }

    var img = z_photoview.querySelector("#zpv_center img.zpv_img");
    if (!img || img.src === location || img.src.slice(-10) === "/blank.gif") {
    return;
    }
    function main() {
    const z_photoview = document.getElementById("z_photoview");
    if (!z_photoview) {
    location = null;
    return;
    }

    var downButton = document.getElementById("down-button");
    const img = z_photoview.querySelector("#zpv_center img.zpv_img");
    if (!img || img.src === location || img.src.slice(-10) === "/blank.gif") {
    return;
    }

    if (!downButton) {
    z_photoview.querySelector(".zpv_bottom_body").insertAdjacentHTML("beforeend", html);
    downButton = document.getElementById("down-button");
    }
    let downButton = document.getElementById("down-button");

    location = img.src;
    // log(img.src);
    if (!downButton) {
    z_photoview.querySelector(".zpv_bottom_body").insertAdjacentHTML("beforeend", html);
    downButton = document.getElementById("down-button");
    }

    if (!downButton.firstChild) {
    var a = document.createElement("a");
    // a.onclick = evClick;
    a.innerText = "save";
    downButton.appendChild(a);
    // log("create link");
    }
    location = img.src;

    downButton.firstChild.href = "http://download-link.lan:81/convert.php?url=" + window.btoa(img.src);
    // log("set href");
    }
    if (!downButton.firstChild) {
    let a = document.createElement("a");
    a.innerText = "save";
    downButton.appendChild(a);
    }

    setInterval(main, 200);
    })();
    downButton.firstChild.href = "http://download-link.lan:81/convert.php?url=" + base64X(img.src);
    }

    setInterval(main, 500);
    })();
  4. dandelionred revised this gist Feb 22, 2020. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions convert.php
    Original file line number Diff line number Diff line change
    @@ -22,10 +22,6 @@ function mapHeaders($list) {
    }, []);
    }

    function println($s) {
    echo $s . PHP_EOL;
    }

    function main() {
    ini_set('display_errors', 0);

  5. dandelionred revised this gist Feb 22, 2020. 1 changed file with 64 additions and 0 deletions.
    64 changes: 64 additions & 0 deletions convert.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php

    /**
    * Decode base64 encoded string with '+/=' replaced with '._-'.
    * @param type $s
    * @return type
    */
    function base64Xd($s) {
    return base64_decode(strtr($s, '._-', '+/='));
    }

    /**
    * Convert $http_response_header into k=>v map.
    * @param Array $list
    * @return Array
    */
    function mapHeaders($list) {
    return array_reduce(array_slice($list, 1), function($carry, $item) {
    list($k, $v) = explode(':', $item, 2);
    $carry[strtolower($k)] = ltrim($v);
    return $carry;
    }, []);
    }

    function println($s) {
    echo $s . PHP_EOL;
    }

    function main() {
    ini_set('display_errors', 0);

    if (isset($_GET['url'])) {
    $url = base64Xd($_GET['url']);

    if ($url !== false) {
    $urlParts = parse_url($url);

    if ($urlParts !== false && ($urlParts['scheme'] === 'http' || $urlParts['scheme'] === 'https')) {
    $filename = basename($urlParts['path']);

    if (strlen($filename)) {
    $response = file_get_contents($url, false, stream_context_create([
    'http' => [
    'user_agent' => $_SERVER['HTTP_USER_AGENT'],
    'timeout' => 10,
    ],
    ]));

    if ($response !== false) {
    $headers = mapHeaders($http_response_header);

    if (isset($headers['content-type'])) {
    header('Content-Type: ' . $headers['content-type']);
    header("Content-Disposition: attachment; filename*=UTF-8''" . urlencode($filename));
    echo $response;
    }
    }
    }
    }
    }
    }
    }

    main();
  6. dandelionred revised this gist Feb 22, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -74,7 +74,6 @@
    }

    downButton.firstChild.href = "http://download-link.lan:81/convert.php?url=" + window.btoa(img.src);
    downButton.firstChild.download = img.src.replace(/^.+\//, "");
    // log("set href");
    }

  7. dandelionred revised this gist Feb 22, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.6
    // @version 0.7
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    @@ -16,15 +16,15 @@
    <style>
    #down-button {
    position: absolute;
    padding-right: 24px;
    height: 48px;
    line-height: 48px;
    bottom: 0;
    right: 0;
    z-index: 2;
    text-align: right;
    }
    #down-button a {
    display: inline-block;
    line-height: 48px;
    padding: 0 24px;
    color: lightgray;
    font-weight: bold;
    font-family: monospace;
  8. dandelionred revised this gist Feb 22, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.5
    // @version 0.6
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    @@ -73,7 +73,7 @@
    // log("create link");
    }

    downButton.firstChild.href = "http://peri.lan/t/down/convert.php?url=" + window.btoa(img.src);
    downButton.firstChild.href = "http://download-link.lan:81/convert.php?url=" + window.btoa(img.src);
    downButton.firstChild.download = img.src.replace(/^.+\//, "");
    // log("set href");
    }
  9. dandelionred revised this gist Feb 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.4
    // @version 0.5
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
  10. dandelionred revised this gist Feb 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -58,7 +58,7 @@
    var downButton = document.getElementById("down-button");

    if (!downButton) {
    z_photoview.insertAdjacentHTML("afterbegin", html);
    z_photoview.querySelector(".zpv_bottom_body").insertAdjacentHTML("beforeend", html);
    downButton = document.getElementById("down-button");
    }

  11. dandelionred revised this gist Feb 21, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.3
    // @version 0.4
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    @@ -58,7 +58,7 @@
    var downButton = document.getElementById("down-button");

    if (!downButton) {
    z_photoview.insertAdjacentHTML("beforeend", html);
    z_photoview.insertAdjacentHTML("afterbegin", html);
    downButton = document.getElementById("down-button");
    }

  12. dandelionred revised this gist Feb 21, 2020. 1 changed file with 20 additions and 4 deletions.
    24 changes: 20 additions & 4 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.2
    // @version 0.3
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    @@ -37,6 +37,12 @@
    console.log("["+(new Date()).getTime()+"] " + s);
    }

    function evClick( ev) {
    // ev.preventDefault();
    // log("click");
    // return false;
    }

    function main() {
    var z_photoview = document.getElementById("z_photoview");
    if (!z_photoview) {
    @@ -57,9 +63,19 @@
    }

    location = img.src;
    // log("img change");
    downButton.innerHTML = "<a href='" + img.src + "'>save</a>";
    // log(img.src);
    // log(img.src);

    if (!downButton.firstChild) {
    var a = document.createElement("a");
    // a.onclick = evClick;
    a.innerText = "save";
    downButton.appendChild(a);
    // log("create link");
    }

    downButton.firstChild.href = "http://peri.lan/t/down/convert.php?url=" + window.btoa(img.src);
    downButton.firstChild.download = img.src.replace(/^.+\//, "");
    // log("set href");
    }

    setInterval(main, 200);
  13. dandelionred revised this gist Feb 21, 2020. 1 changed file with 39 additions and 15 deletions.
    54 changes: 39 additions & 15 deletions vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @version 0.2
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    @@ -12,30 +12,54 @@

    var location = null;

    var html = `
    <style>
    #down-button {
    position: absolute;
    padding-right: 24px;
    height: 48px;
    line-height: 48px;
    bottom: 0;
    right: 0;
    z-index: 2;
    text-align: right;
    }
    #down-button a {
    color: lightgray;
    font-weight: bold;
    font-family: monospace;
    }
    </style>
    <div id="down-button"></div>
    `;

    function log( s) {
    console.log("["+(new Date()).getTime()+"] " + s);
    }

    function main() {
    if (document.location.href === location) {
    var z_photoview = document.getElementById("z_photoview");
    if (!z_photoview) {
    location = null;
    return;
    }

    var img = document.querySelector("#zpv_center img.zpv_img");
    if (!img || img.src.slice(-10) === "/blank.gif") {
    var img = z_photoview.querySelector("#zpv_center img.zpv_img");
    if (!img || img.src === location || img.src.slice(-10) === "/blank.gif") {
    return;
    }

    var tdList = document.querySelectorAll(".like_box td");
    var downButton = document.getElementById("down-button");

    if (tdList.length !== 3) {
    return;
    if (!downButton) {
    z_photoview.insertAdjacentHTML("beforeend", html);
    downButton = document.getElementById("down-button");
    }

    location = document.location.href;

    var td0 = tdList[2];
    var td1 = document.createElement("td");
    td1.className = "row_table_last_column";
    td1.innerHTML = "<a href='" + img.src + "' class='item_button'><i class='i_icon' style='background-position: 0 -72px;'></i></a>";
    td0.className = td0.className.replace("row_table_last_column", "row_table_column");
    td0.parentNode.appendChild(td1);
    location = img.src;
    // log("img change");
    downButton.innerHTML = "<a href='" + img.src + "'>save</a>";
    // log(img.src);
    }

    setInterval(main, 200);
  14. dandelionred renamed this gist Feb 21, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions vk-image-save.js → vk-image-save.user.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @downloadURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @updateURL https://gist.github.com/dandelionred/8c6059be4b2fdc55bb990baea8298a67/raw/vk-image-save.user.js
    // @match https://m.vk.com/*
    // ==/UserScript==

  15. dandelionred revised this gist Feb 21, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions vk-image-save.js
    Original file line number Diff line number Diff line change
    @@ -34,8 +34,6 @@
    td1.innerHTML = "<a href='" + img.src + "' class='item_button'><i class='i_icon' style='background-position: 0 -72px;'></i></a>";
    td0.className = td0.className.replace("row_table_last_column", "row_table_column");
    td0.parentNode.appendChild(td1);

    console.log(img.src);
    }

    setInterval(main, 200);
  16. dandelionred created this gist Feb 21, 2020.
    42 changes: 42 additions & 0 deletions vk-image-save.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    // ==UserScript==
    // @name vk image save
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @match https://m.vk.com/*
    // ==/UserScript==

    (function() {
    'use strict';

    var location = null;

    function main() {
    if (document.location.href === location) {
    return;
    }

    var img = document.querySelector("#zpv_center img.zpv_img");
    if (!img || img.src.slice(-10) === "/blank.gif") {
    return;
    }

    var tdList = document.querySelectorAll(".like_box td");

    if (tdList.length !== 3) {
    return;
    }

    location = document.location.href;

    var td0 = tdList[2];
    var td1 = document.createElement("td");
    td1.className = "row_table_last_column";
    td1.innerHTML = "<a href='" + img.src + "' class='item_button'><i class='i_icon' style='background-position: 0 -72px;'></i></a>";
    td0.className = td0.className.replace("row_table_last_column", "row_table_column");
    td0.parentNode.appendChild(td1);

    console.log(img.src);
    }

    setInterval(main, 200);
    })();