如何停止 chrome/firefox 下載 gif?

如何停止 chrome/firefox 下載 gif?

當我訪問任何包含一些動畫的頁面gif(Google+、9gag 等)時,所有這些似乎都開始加載。我的頻寬有限,除非我真的想查看,否則我不想下載這些內容。我看過一些插件就停止了卡通但圖像本身是下載的反正。 9gag.com 最初有這個功能,它只顯示靜態圖像(如果它是動畫 gif),並且僅在我單擊它後才開始下載(他們現在已將其刪除)。

那有沒有什麼插件可以阻止下載動圖?或者我需要寫一個擴充功能嗎?有什麼建議嗎?

答案1

我還沒有任何合適的擴充功能/插件。我嘗試使用以下用戶腳本篡改猴在 Chrome 中。它工作得很好。封鎖 9gag.com 網站中的所有 gif(包括 ajax gif)。由於某種原因,google+ 中的 ajax gif 不會被阻止(對此進行調查)。非常感謝賽尼泰克感謝他的幫助、努力和代碼。這是使用者腳本(大部分腳本是從Synetec 的使用者腳本):

// ==UserScript==
// @name       gifBlock
// @namespace  http://i.have.no.homepage/
// @version    0.1
// @description  Stops downloading gif images (including ajax gifs) in 9gag.com (or any page if you just fix the @match rule)
// @match      http://*.9gag.com
// @copyright  2012+, Nobody
// ==/UserScript==

function tamperMonkeyWrap()
{   
    function log(m)
    {
        console.log(m);
    }
    function jQWrap($)
    {
        log("Extension execution begins...");

        function blockGifs()
        {        
            $('img').each(function() {
                var $img = $(this),
                    src = $img.attr('src'),
                    w = $img.width(),
                    h = $img.height(),
                    cursor = $img.css('cursor'),
                    parts = src.split('.'),
                    ext = parts[parts.length-1];

                if ($.trim(ext.toLowerCase()) != "gif")
                    return;            

                $img.attr('data-imgurl', src);
                $img.data('cursor', cursor);
                $img.css('cursor', 'pointer');
                $img.addClass('gif-blocked');                
                h = h > 100? h : 100;
                $img.attr('src', '//ipsumimage.appspot.com/'+w+'x'+h+'?l=Gif (Click)');
            }); 
        }

        function interceptAjax () {
            $('body').ajaxComplete(
                function (event, requestData)
                {
                    log("Blocking GIF [Ajax] ...");                
                    blockGifs();
                }
            );
        }

        $(document).ready(function() {
            log("Blocking GIF [Ready]....");
            blockGifs();
            interceptAjax();        
            $(document).on('click', 'img.gif-blocked', function(ev) {            
                var $img = $(this),
                    url = $img.attr('data-imgurl'),
                    cursor = $img.data('cursor');

                $img.attr('src', url);
                $img.css('cursor', cursor);
                $img.removeClass('gif-blocked');
                ev.preventDefault();
                return false;
            });  
        });

        log("Document is not ready yet. trying block just in case it takes time to be _ready_ (google+).");
        blockGifs();
    }

    if (window.jQuery == undefined)
    {
        log("Loading jQuery...");
        var scriptTag = document.createElement('script');
        scriptTag.src = "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
        scriptTag.onload = function(){
            log("jQuery loaded.");
            window.jQuery = jQuery; 
            jQWrap(jQuery);
        };
        document.getElementsByTagName('head')[0].appendChild(scriptTag);
    }
    else
    {
        log("jQuery already included in the page");
        jQWrap(window.jQuery);
    }   
}

var scriptTag = document.createElement('script');
scriptTag.text = '(' + tamperMonkeyWrap.toString() + ')();';
document.getElementsByTagName('head')[0].appendChild(scriptTag);

現在:

  1. 安裝 TamperMonkey
  2. 轉到儀表板
  3. 點擊“新腳本”
  4. 貼上上面的程式碼
  5. 保存看看是否有效。 (現在僅適用於 9gag.com。但是您可以更改指令@match以匹配您想要的任何網站。使用@match http://*/*適用於所有網站 (http)。更改https為適用於任何安全的 http 網站,例如 google+)

答案2

一些不錯的 Firefox 外掛:

adblock - 智慧攔截廣告

flashblock - 所有閃光燈都將被阻止,直到您不點擊它們

imgblock - 阻止所有圖像,無處不在(可以透過點擊暫時停用)

Ghostery - 阻止社交網站(它們可以使每個頁面訪問增加數百位元組!)

相關內容