如何从twitter小部件中获取徽标

Jus*_*mac 3 html javascript css twitter

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

现在我得到这个代码:

<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>
Run Code Online (Sandbox Code Playgroud)

当我将其嵌入我的网站时,我会在左上角看到我的徽标.有没有可能把它拿出来?

它引用了这个脚本:http://widgets.twimg.com/j/2/widget.js

任何帮助,将不胜感激.

谢谢

小智 9

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

.twtr-hd, .twtr-ft{display: none;}
Run Code Online (Sandbox Code Playgroud)

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


Mar*_*pel 6

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

var logo = isHttps ? 'https://twitter-widgets.s3.amazonaws.com/i/widget-logo.png' : 'http://widgets.twimg.com/i/widget-logo.png';
Run Code Online (Sandbox Code Playgroud)

并在这里嵌入HTML:

<a target="_blank" href="http://twitter.com"><img alt="" src="' + logo + '"></a>
Run Code Online (Sandbox Code Playgroud)

所以你应该放弃那部分而你已经完成了.

也就是说,我想知道这是不是违反了许可协议.


更新:上面的方法确实删除了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>
Run Code Online (Sandbox Code Playgroud)

所以这只是找到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;
}
Run Code Online (Sandbox Code Playgroud)

我非常怀疑删除调用的行setProfileImage就足够了:

this.setProfileImage(resp[0].user.profile_image_url);
Run Code Online (Sandbox Code Playgroud)

你唯一注意到的是标题现在距离右边太远了.您必须覆盖此CSS规则:

.twtr-widget-profile h3, .twtr-widget-profile h4 {
    margin: 0 0 0 40px !important;
}
Run Code Online (Sandbox Code Playgroud)