javascript 如何从 Twitter 小部件中获取徽标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4147381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:30:09  来源:igfitidea点击:

How to get logo out of twitter widget

javascripthtmlcsstwitter

提问by Justmac

I am using the Twitter widget from Twitter itself. You can download it at http://twitter.com/about/resources/widgets/widget_profile

我正在使用 Twitter 本身的 Twitter 小部件。您可以在http://twitter.com/about/resources/widgets/widget_profile下载它

Now i get this code:

现在我得到这个代码:

<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 6000,
  width: 180,
  height: 320,
  theme: {
    shell: {
      background: '#6e6e6e',
      color: '#ffffff'
    },
    tweets: {
      background: '#fefefe',
      color: '#545454',
      links: '#b05c5c'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('SchmidtGlobal').start();
</script>

When I embed this in my website I get my logo at the top left side. Is there any possibility to get this out?

当我将其嵌入我的网站时,我的徽标位于左上角。有没有可能把这个弄出来?

It's refereing to this script: http://widgets.twimg.com/j/2/widget.js

它指的是这个脚本:http://widgets.twimg.com/j/2/widget.js

Any help would be appreciated.

任何帮助,将不胜感激。

Thanks

谢谢

回答by Queen of the Nerds

The easiest way would be to use CSS. Create a CSS document and link it to your web page. In the css paste:

最简单的方法是使用 CSS。创建一个 CSS 文档并将其链接到您的网页。在 css 粘贴中:

.twtr-hd, .twtr-ft{display: none;}

This will remove the header and footer. Hope this helps!

这将删除页眉和页脚。希望这可以帮助!

回答by Marcel Korpel

In the full sourcethe location of the logo is defined here:

完整的源代码中,徽标的位置在此处定义:

var logo = isHttps ? 'https://twitter-widgets.s3.amazonaws.com/i/widget-logo.png' : 'http://widgets.twimg.com/i/widget-logo.png';

and embedded in HTML here:

并在此处嵌入 HTML:

<a target="_blank" href="http://twitter.com"><img alt="" src="' + logo + '"></a>

So you should just drop that part and you're done.

所以你应该放弃那部分,你就完成了。

That said, I wonder if this isn't against the license agreement.

也就是说,我想知道这是否违反许可协议。



UPDATE:Above method indeed removes the Twitter logo, as the OP suspected, but it is not that difficult to remove the profile image. A look at the resulting widget (using 'Test Settings') shows me that the image's markup is

更新:上述方法确实删除了 Twitter 徽标,正如 OP 所怀疑的那样,但删除个人资料图片并不难。查看生成的小部件(使用“测试设置”)告诉我图像的标记是

<a class="twtr-profile-img-anchor" href="http://twitter.com/***" target="_blank">
    <img src="http://a1.twimg.com/profile_images/***/***.jpg" class="twtr-profile-img" alt="profile">
</a>

so it's just a matter of finding code that sets class twtr-profile-img-anchorin the source code. And look, it's there:

所以这只是twtr-profile-img-anchor源代码中找到设置类的代码的问题。看,它在那里:

/**
  * @public
  * @param {string}
  * sets the profile image source to display in the widget
  * @return self
  */
setProfileImage: function(url) {
  this._profileImage = url;
  this.byClass('twtr-profile-img', 'img').src = isHttps ? url.replace(httpsImageRegex, httpsImageReplace) : url;
  this.byClass('twtr-profile-img-anchor', 'a').href = 'http://twitter.com/' + this.username;
  return this;
}

I highly suspect that removing the line that calls setProfileImagewill suffice:

我高度怀疑删除调用的行setProfileImage就足够了:

this.setProfileImage(resp[0].user.profile_image_url);

The only thing you'll notice is that the header will now be too far to the right. You'll have to override this CSS rule:

您会注意到的唯一一件事是标题现在离右侧太远了。您必须覆盖此 CSS 规则:

.twtr-widget-profile h3, .twtr-widget-profile h4 {
    margin: 0 0 0 40px !important;
}

回答by Ahmed

find twtr-hdin the script, add

在脚本中找到twtr-hd,添加

style="display:none"

find twtr-ftin the script, add

在脚本中找到twtr-ft,添加

style="display:none"

this should do it.

这应该这样做。

inspired by the Queen of Nerds' solution

灵感来自书呆子女王的解决方案