npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tencent-share-midoci

v1.0.0

Published

该模块集成了微信、QQ、腾讯新闻客户端、腾讯视频客户端的分享API,可以设置分享的标题、描述、图片和链接

Downloads

11

Readme

设置分享信息

该模块集成了微信、QQ、腾讯新闻客户端、腾讯视频客户端的分享API,可以设置分享的标题、描述、图片和链接。

请注意: 当前功能只能在*.qq.com域名的网页中使用,其他域名调用当前模块是没有效果的。

0.1.01.0.0进行了较大版本的更新,必须使用new关键创建实例,然后使用实例调用相关的方法,同时可以监听微信的分享事件。

1. 使用方式

import Share from 'tencent-share';

// 分享信息
var shareData = {
    title: '读腾讯新闻,助力公益事业,让你的时间更有意义',
    desc: '上腾讯新闻,捐阅读时长做公益,一起为爱聚力',
    img: 'http://mat1.gtimg.com/news/qqnews/qqspring/img/logo.png',
    link: window.location.href
};

const share = new Share(shareData);
share.setShareInfo(shareData)
    .on('share', data=>console.log('share', data)) // 监听分享事件
    .on('success', data=>console.log('success', data)) // 监听分享成功事件
    .on('cancel', data=>console.log('cancel', data)) // 监听取消分享的事件

2. setShareInfo

setShareInfo为总方法,调用该方法后,开发者无需关心当前处于什么环境,模块会自动根据UA设置微信、QQ、腾讯新闻客户端、腾讯视频客户端的分享信息。

如果想在不同的环境里设置的信息,下面的这几个方法可以调用:

  • setShareInWx(shareData, type) : 设置页面在微信中的分享信息,type字段稍后讲解;
  • setShareInQQ(shareData) : 设置页面在QQ中的分享信息;
  • setShareInNews(shareData) : 设置页面在新闻客户端中的分享信息;
  • setShareInVideo(shareData) : 设置页面在腾讯视频中的分享信息;

在设置页面在微信中的分享信息的方法里,有个type字段,这个type字段能设置在微信中分别分享给好友、朋友圈、QQ和QQ空间的信息。

setShareInWx(shareData, 'friends')表示分享给好友时的分享信息,type字段有:

  • friends : 分享给好友
  • timeline : 分享到朋友圈
  • qq : 分享给QQ好友
  • qzone : 分享到QQ空间

3. 呼起分享面板

新闻客户端内设置分享信息后,还可以调用show()方法来主动呼起分享面板:

share.show(); // 该方法只在新闻客户度内有效

同时,还可以在 Android版的新闻客户端 内,禁止该页面的分享功能:

share.forbidShare();