12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { faceShareRedirectUrl } from '@/http/configAPI'
- let tempData = {
- publishContentStr: ''
- }
- /**
- * 初始化contentjs调用逻辑
- */
- export function initFacebookContent() {
- // window.location.href.indexOf('facebook.com') > -1;
- injectShareCode();
- shareCallback();
- };
- /**
- * 设置发布内容字符串
- */
- export function setPublishString(params) {
- let { publishContentStr} = params.data || {};
- tempData.publishContentStr = publishContentStr;
- }
- /**
- * 注入分享页面逻辑
- * @returns
- */
- function injectShareCode() {
- const {href, pathname} = window.location;
- if(!(href.indexOf('facebook.com') > -1 && pathname.indexOf('dialog/share'))) {
- return;
- }
- // 设置分享内容
- setShareInputContent();
- }
- /**
- * 格式化发布内容字符串
- */
- function formatContentStr(content) {
- let str = content.replace(/(\r)/g,'\n');
- return str;
- }
- /**
- * 设置分享输入框内容
- */
- function setShareInputContent() {
- const contentStr = formatContentStr(tempData.publishContentStr);
- if (!tempData.isSetContent && contentStr) {
- tempData.isSetContent = true;
- setTimeout(() => {
- document.execCommand("insertText", false, contentStr);
- setTimeout(() => {
- tempData.isSetContent = false;
- }, 800)
- }, 600);
- }
- }
- /**
- * 分享回调
- */
- function shareCallback() {
- if (window.location.href.indexOf(faceShareRedirectUrl) > -1) {
- tempData.publishContentStr = '';
- const urlParams = new URLSearchParams(window.location.search);
- let params = JSON.parse(urlParams.get('params'));
- if (params) {
- chrome.runtime.sendMessage({ actionType: "CONTENT_FACEBOOK_SHARE_SUCCESS", data: params }, () => {
- })
- }
- }
- }
|