脸书情绪

发布于 2024-11-08 00:29:31 字数 1372 浏览 3 评论 0原文

此代码来自 Facebook 聊天表情栏 Grease Monkey UserScript

ImagesURL = HttpsOn?'https://s-static.ak.fbcdn.net/images/':'http://static.ak.fbcdn.net/images/';


emotsInfo = [':)', ':(', ':p', ':D', ':o', ';)', '8)', '8|', '>:(', ':/', ':\'(', '3:)', 'O:)', ':*', '<3', '^_^', '-_-', 'o.O', '>:O', ':v', ':3'];



for(i=0;i<emotsInfo.length;i+=1) {
        var fEmotsDom = document.createElement('img');
        fEmotsDom.setAttribute('alt',emotsInfo[i]);
        fEmotsDom.setAttribute('style','cursor: pointer; background-position: -'+ 16*i +'px 0px;');
        fEmotsDom.setAttribute('src',ImagesURL + 'blank.gif');
        fEmotsDom.setAttribute('class','emote_img');
        fEmotsListDom.appendChild(fEmotsDom);
    }


此代码从 Facebook 服务器带来 Facebook 表情
我正在编写 WPF 代码,除了从空白.gif 中获取情感之外,我了解所有代码过程

C# 代码

        const string EmotionsResources = "http://static.ak.fbcdn.net/images/";


        private Image Emoticons ( string E )
        {
            return ( new Image ( ) { Source = new BitmapImage ( new Uri ( EmotionsResources + E ) ) } );
        }


如果您尝试获取任何 Facebook 聊天情绪的来源..您将得到 [ http://static.ak.fbcdn.net/images/blank.gif ] 这段代码如何从此链接检索情绪?

This code is from Facebook Chat Emoticons Bar Grease Monkey UserScript

ImagesURL = HttpsOn?'https://s-static.ak.fbcdn.net/images/':'http://static.ak.fbcdn.net/images/';


emotsInfo = [':)', ':(', ':p', ':D', ':o', ';)', '8)', '8|', '>:(', ':/', ':\'(', '3:)', 'O:)', ':*', '<3', '^_^', '-_-', 'o.O', '>:O', ':v', ':3'];



for(i=0;i<emotsInfo.length;i+=1) {
        var fEmotsDom = document.createElement('img');
        fEmotsDom.setAttribute('alt',emotsInfo[i]);
        fEmotsDom.setAttribute('style','cursor: pointer; background-position: -'+ 16*i +'px 0px;');
        fEmotsDom.setAttribute('src',ImagesURL + 'blank.gif');
        fEmotsDom.setAttribute('class','emote_img');
        fEmotsListDom.appendChild(fEmotsDom);
    }

This code brings Facebook emotions from Facebook server
I'm coding a WPF , I understand all code procedures except getting the emotion from blank.gif

C# Code

        const string EmotionsResources = "http://static.ak.fbcdn.net/images/";


        private Image Emoticons ( string E )
        {
            return ( new Image ( ) { Source = new BitmapImage ( new Uri ( EmotionsResources + E ) ) } );
        }

if you try to get source of any of Facebook chat emotions .. you will get [ http://static.ak.fbcdn.net/images/blank.gif ]
this code retrieve emotions from this link HOW ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-11-15 00:29:31

我在这里猜测,但我认为该类会触发一种检查替代文本的样式。 (一旦你划掉了所有不可能的答案,这是唯一有效的答案。每次迭代中唯一改变的是替代文本,所以这一定是触发它的内容。CSS类选择器可以处理属性值)

并且在换句话说——你被困住了。


编辑

所以我很感兴趣,所以我开始更深入地挖掘:

图像上的CSS样式包含以下CSS规则:

element.style {
background-position: 0px 0px;
}
.emote_img {
background: url(http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png) no-repeat;
overflow: hidden;
}

第一个由脚本设置,第二个来自CSS文件。

所以。实际图像可以在该 png 文件中找到,即:

http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png
Facebook 表情符号sprite

(很高兴知道你可以在 Facebook 中使用这么多表情符号!:-)

,你会在一张图像中看到所有图像(这样做是为了节省带宽)
由于图像尺寸为16*16,因此一次仅显示一张图像。
背景位置的东西负责移动图像,以便每次从大图像中显示不同的图标。


因此,要在 C# 中获取图像,您将执行以下操作:

您可以裁剪它,或者使用完全相同的技巧(在我看来这是更好的方法),如下所示:

<Canvas ClipToBounds="true" Width="16" Height="16">
    <Image Source="http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png" 
       Canvas.Left="0" /> <!-- or -16, -32, -48 etc.. -->
</Canvas>

I'm guessing here, but I think that the class triggers a style that checks the alt text. (that's the only valid answer once you cross-off all the impossible answers.. the only thing that changes in each iteration is the alt text so that must be what's triggering it. and a css class selector can work on attribute values)

and in other words - you're stuck.


Edit

So i was intrigued so i started to dig a bit deeper:

css style on the image has the following css rules in it:

element.style {
background-position: 0px 0px;
}
.emote_img {
background: url(http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png) no-repeat;
overflow: hidden;
}

the first one is set by the script, and the second comes from the CSS file.

so. the actual images are found in that png file, which is:

http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png:
facebook emoticon sprite

(cool to know u can use so many emoticons in fb! :-)

and you'll see ALL of the images in one image (it's done to preserve bandwidth)
since the image size is 16*16, it only shows ONE image at a time.
the background-position thingie is in charge of shifting the image, so that each time a different icon is shown from the big image.


So to get the image in C# you'll do the following:

you can either crop it, or use the exact same trick (which is better IMO), like this:

<Canvas ClipToBounds="true" Width="16" Height="16">
    <Image Source="http://static.ak.fbcdn.net/rsrc.php/v1/zC/r/eKCEtE1PXyK.png" 
       Canvas.Left="0" /> <!-- or -16, -32, -48 etc.. -->
</Canvas>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文