Greasy Fork

来自缓存

Greasy Fork is available in English.

Better ifeng.com Pictures 凤凰网 图片尺寸修复及键盘左右页面切换

如题

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Better ifeng.com Pictures 凤凰网 图片尺寸修复及键盘左右页面切换
// @namespace   feifeihang.info
// @description 如题
// @include     http://*.ifeng.com/*
// @include     https://*.ifeng.com/*
// @version     1
// @grant       none
// ==/UserScript==
(function (window, document, undefined) {
  var LEFT = 37;
  var RIGHT = 39;
  var style = document.createElement('style');
  var css = 'body {width: 100% !important;}' +
  '#picDiv {border: none;}' +
  '#photoimg {display: block !important;} img#photo {width: 100% !important;}';
  style.appendChild(document.createTextNode(css));
  document.body.appendChild(style);
  // set #imgBox width to window.innerWidth - 20px.
  var box = document.querySelector('#imgBox');
  if (box) {
    box.style.maxWidth = box.style.width = (window.innerWidth - 20) + 'px !important';
    window.addEventListener('resize', function () {
      box.style.maxWidth = box.style.width = (window.innerWidth - 20) + 'px !important';
    }, true);
    // bind left and right arrow keys for turning pages if there are page-turning anchors.
    var prev = document.querySelector('a.picPrev');
    var next = document.querySelector('a.picNext');
    if (prev || next) {
      window.addEventListener('keypress', function (evt) {
        // only turn page if no inputs or textareas are active.
        var inputs = document.querySelectorAll('input[type=text], textarea');
        inputs = Array.prototype.slice.apply(inputs);
        if (inputs.indexOf(document.activeElement) === - 1) {
          if (evt.keyCode === LEFT && prev) {
            evt.preventDefault();
            prev.click();
          } 
          else if (evt.keyCode === RIGHT && next) {
            evt.preventDefault();
            next.click();
          }
        }
      });
    }
  }
}) (window, document);