m-team https fix

Convert in-site http links to https

От 28.02.2016. Виж последната версия.

// ==UserScript==
// @name        m-team https fix
// @namespace   m-team
// @version     0.9
// @grant       none
// @include     https://tp.m-team.cc/*
// @description Convert in-site http links to https
// @description:zh-CN 将站内 http 链接转换为 https
// @description:zh-TW 將站內 http 鏈接轉換為 https
// ==/UserScript==

//替换 http 链接为 https
(function () {
  var snapResults = document.evaluate('//a[starts-with(@href,\'http://tp.m-team.cc/\')]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  for (var i = snapResults.snapshotLength - 1; i >= 0; i--) {
    var elm = snapResults.snapshotItem(i);
    var href = elm.getAttribute('href');
    href = href.replace(/^http/, 'https');
    elm.setAttribute('href', href);
  }
}) ();
//替换 站内图片 地址为 https
(function () {
  var snapResults = document.evaluate('//img[starts-with(@src,\'http://img.m-team.cc/\')]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  for (var i = snapResults.snapshotLength - 1; i >= 0; i--) {
    var elm = snapResults.snapshotItem(i);
    var attrs = elm.attributes;
    for (var j = attrs.length - 1; j >= 0; j--) {
      var name = attrs[j].name;
      var value = attrs[j].value;
      elm.setAttribute(name, value.replace(/http(:\/\/img\.m-team\.cc)/gi, 'https$1'));
    }
  }
}) ();
//替换默认 download 链接为 https tracker 版本
(function () {
  var snapResults = document.evaluate('//a[starts-with(@href, \'download.php?\')]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  for (var i = snapResults.snapshotLength - 1; i >= 0; i--) {
    var elm = snapResults.snapshotItem(i);
    var href = elm.getAttribute('href');
    href = href + '&https=1';
    elm.setAttribute('href', href);
  }
}) ();