【发布时间】:2019-07-03 08:09:51
【问题描述】:
我是 Javascript 和 jQuery 的初学者,并试图删除 twitter 时间线中的所有图标。
我想要做的是,动态删除 twitter-timeline 中的所有图标(我的意思是,每次按下“查看新推文”按钮时),并且用随机选择的颜色重新编写每个图标。
这是我的代码。
// 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 个或少数几个图标的顶部。
- 不是动态工作。当按下“新推文”按钮时,图标会自行显示。
- icon-backgroundcolor 仍未改变。
如果您知道如何解决此问题,我将不胜感激。 谢谢。
【问题讨论】:
标签: javascript jquery twitter google-chrome-extension