Exhobby For Hpoi

Add exhobby for hpoi.net

目前為 2019-04-29 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @icon            http://res.hpoi.net.cn/gk/res/img/favicon.ico
// @name            Exhobby For Hpoi
// @namespace       [url=exhobby.net]exhobby[/url]
// @author          exhobby
// @description     Add exhobby for hpoi.net
// @match           *://*.hpoi.net/hobby/*
// @match           *://*.hpoi.net/album/*
// @match           *://*.hpoi.net.cn/hobby/*
// @match           *://*.hpoi.net.cn/album/*
// @version         0.0.2
// @grant           GM_addStyle
// @grant           GM_xmlhttpRequest
// @grant           GM_download
// ==/UserScript==
(function () {
    'use strict';
    var base_url_n = "http://res.exhobby.net/pic/n/"
    , base_url_s = "http://res.exhobby.net/pic/s/"
    , tmp = $("#addfav").attr("onclick")
    , type = tmp.indexOf('addFav2') == -1 ? "hobby" : "album";
  var fav = ""
    , target = "";
  if (type == "hobby") {
      fav = tmp.substring(tmp.indexOf("('") + 2, tmp.indexOf("')")),
      target = ".light-gallery"
  } else {
      fav = tmp.substring(tmp.indexOf("('") + 2, tmp.indexOf("',")),
      target = ".avia_desktop"
  }
  var template = '<div class="col-sm-4 col-xs-6" style="padding:1px">' + '<div class="flow-outer">' + '<a class="outside-pic" target="_blank" href="{url}">' + '<img class="flow-img b-lazy b-loaded flow-img-land" src="{root_s}{path}">' + '</a>' + '</div></div>'
    , loading = '';
  function addPics(url) {
      var content = '<div class="ibox"><div class="ibox-title"><h5>ExHobby</h5><div class="ibox-tools"><a class="pull-right" target="_blank" href="' + url + '"><span class="label label-info">More</span></a></div></div><div class="ibox-content"><div class="row outside-pics"></div></div></div>';
      $(content).insertAfter($(target).closest(".ibox"))
  }
  $('<div id="exhobby-loading" style="margin-bottom:20px;"><div style="float:left;line-height: 22px;padding-left: 30px;">Exhobby Loading...</div><div style="margin-left: 0px;" class="sk-spinner sk-spinner-circle"><div class="sk-circle1 sk-circle"></div> <div class="sk-circle2 sk-circle"></div><div class="sk-circle3 sk-circle"></div><div class="sk-circle4 sk-circle"></div><div class="sk-circle5 sk-circle"></div><div class="sk-circle6 sk-circle"></div><div class="sk-circle7 sk-circle"></div><div class="sk-circle8 sk-circle"></div><div class="sk-circle9 sk-circle"></div><div class="sk-circle10 sk-circle"></div><div class="sk-circle11 sk-circle"></div><div class="sk-circle12 sk-circle"></div></div></div>').insertAfter($(target).closest(".ibox"));

  GM_xmlhttpRequest({
        method: 'POST',
        url: 'http://www.exhobby.net/get/pic?id='+fav,
        onload: response => {
            $("#exhobby-loading").remove()

            var rs=JSON.parse(response.responseText);  
            console.log(rs);
            
            if (rs.map.list && rs.map.list.length > 0) {
                addPics(rs.map.url);
                for (var k in rs.map.list) {
                    var _a = template;
                    _a = _a.replace(/{url}/g, rs.map.url).replace(/{root_s}/g, base_url_s).replace(/{path}/g, rs.map.list[k].path).replace(/{itemId}/, rs.map.list[k].picId);
                    $(".outside-pics").append(_a)
                }
                $('.flow-img').each(function() {
                    if ($(this)[0].width / $(this)[0].height > $(this).parent().parent('div').width() / $(this).parent().parent('div').height()) {
                        $(this).addClass('flow-img-land')
                    }
                });
                $('.flow-img').load(function() {
                    if ($(this)[0].width / $(this)[0].height > $(this).parent().parent('div').width() / $(this).parent().parent('div').height()) {
                        $(this).addClass('flow-img-land')
                    } else {
                        $(this).removeClass('flow-img-land')
                    }
                })
            }
        }
    });
})();