如何通过jQuery的动态改写Twitter的图片?

问题描述 投票:0回答:1

我的Javascript和jQuery的新手,并试图删除Twitter的时间表所有图标。

我想要做的是,动态删除Twitter的时间轴中的所有图标(我的意思是,每次当“见新的鸣叫”按钮被按下),并且还重新编写由随机选择的颜色每个图标。

所以,我现在要做的就是这个样子。 https://photos.google.com/share/AF1QipNU-ct8h6oA1_-QNgA4rLNrBpmdbULS-THe3Zt6FONNkxhMwI4rrBT-x0weyRq7YA?key=dDhHaENQNzkzLVYwYm5zUWczTF9XVl9RdFpGYUVB

这里是我的代码。

// If class containts 'avatar', just rewrite.

// rewrite for each tag https://symfoware.blog.fc2.com/blog-entry-1515.html

$(function(){
    $("img").each(function(){

      // https://stackoverflow.com/questions/3196613/jquery-determine-if-ul-has-class-or-another-one

        if ($('img').hasClass('Avatar Avatar--size32') ||
           $('img').hasClass('avatar size32') ||
           $('img').hasClass('DashboardProfileCard-avatarImage js-action-profile-avatar') ||
           $('img').hasClass('avatar js-action-profile-avatar ') ||
           $('img').hasClass('top-timeline-tweet-box-user-image avatar size32') ||
           $('img').hasClass('avatar js-action-profile-avatar ') ||
           $('img').hasClass('avatar js-action-profile-avatar') ||
           $('img').hasClass('MomentUserByline-avatar') ||
           $('img').hasClass('ProfileAvatar-image') ||
           $('img').hasClass('ProfileCardMini-avatarImage')
        ) {
          // https://peacepopo.net/blog-entry-161.html
          var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
          // Rewrite image to random colors
          // http://shanabrian.com/web/jquery/image01.php

          var stylechar = "background-color:" + hue
           $("img").removeAttr('src');
           $("img").attr('style',stylechar);
      }
    });
});


一些图标被删除,但也有很多的问题。的问题是,

  • 仅在时间轴2个或几个图标,顶部被移除。
  • 不工作动态。当“新的微博”按钮时,图标显示为本身。
  • 图标backgroundColor时仍然没有改变。

如果你知道如何可以是固定的,我将非常感激。谢谢。

javascript jquery twitter google-chrome-extension
1个回答
0
投票

你没有说你的代码被设置为执行(你应该把它记录在您的清单空闲)。这可以帮助一些,但你会需要一些事件的Twitter的的动态变化的内容。把你的代码中的函数,那么你可以听点击了“看新的鸣叫”按钮或设置一个突变观察员再次执行你的函数的页面更改时。

© www.soinside.com 2019 - 2024. All rights reserved.