|
@@ -53,8 +53,8 @@ export function backTwitterPinLoginCode(code) {
|
|
|
* 渲染要插入的dom,初始化逻辑
|
|
|
* @param port
|
|
|
*/
|
|
|
-export function renderDom (port) {
|
|
|
- if(window.location.href.indexOf('https://twitter.com') > -1) {
|
|
|
+export function renderDom(port) {
|
|
|
+ if (window.location.href.indexOf('https://twitter.com') > -1) {
|
|
|
_createBtnDom(port);
|
|
|
setTimeout(() => {
|
|
|
_addIframe();
|
|
@@ -68,26 +68,26 @@ export function renderDom (port) {
|
|
|
* 展示give弹窗
|
|
|
*/
|
|
|
export function showGiveDialogHandler() {
|
|
|
- dom.iframe.contentWindow.postMessage({actionType : 'CONTENT_SHOW_GIVE_DIALOG'}, '*');
|
|
|
+ dom.iframe.contentWindow.postMessage({ actionType: 'CONTENT_SHOW_GIVE_DIALOG' }, '*');
|
|
|
}
|
|
|
|
|
|
-export function showIframeHandler () {
|
|
|
+export function showIframeHandler() {
|
|
|
dom.iframe.style.display = 'block';
|
|
|
}
|
|
|
|
|
|
-export function hideIframeHandler () {
|
|
|
+export function hideIframeHandler() {
|
|
|
dom.iframe.style.display = 'none';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 展示twitter原生发布框
|
|
|
*/
|
|
|
-export function showTwitterPublishDialogHandler () {
|
|
|
+export function showTwitterPublishDialogHandler() {
|
|
|
dom.tweetBtn.click();
|
|
|
_publishTweetEvent();
|
|
|
}
|
|
|
|
|
|
-function getUserInfo (cb) {
|
|
|
+function getUserInfo(cb) {
|
|
|
getChromeStorage('userInfo', (res) => {
|
|
|
cb && cb(res);
|
|
|
})
|
|
@@ -97,7 +97,7 @@ function getUserInfo (cb) {
|
|
|
* 监听dialog内点击原生发布按钮事件
|
|
|
* @private
|
|
|
*/
|
|
|
- function _publishTweetEvent (cb) {
|
|
|
+function _publishTweetEvent(cb) {
|
|
|
let publishTweetBtn = document.querySelector('div[role="dialog"]').querySelector('div[data-testid="tweetButton"]');
|
|
|
publishTweetBtn.addEventListener('click', function () {
|
|
|
setTimeout(() => {
|
|
@@ -114,7 +114,7 @@ function getUserInfo (cb) {
|
|
|
* @param isClick
|
|
|
* @private
|
|
|
*/
|
|
|
-function _addDeNetEditBtn (parent, dom, isClick = false) {
|
|
|
+function _addDeNetEditBtn(parent, dom, isClick = false) {
|
|
|
setTimeout(() => {
|
|
|
if (parent) {
|
|
|
parent.parentNode.insertBefore(dom, parent.nextSibling);
|
|
@@ -131,7 +131,7 @@ function _addDeNetEditBtn (parent, dom, isClick = false) {
|
|
|
* 在dialog插入deNet按钮
|
|
|
* @private
|
|
|
*/
|
|
|
-function _addDeNetBtnToDialog () {
|
|
|
+function _addDeNetBtnToDialog() {
|
|
|
setTimeout(() => {
|
|
|
let dialogScheduleBtn = _getScheduleDom(true);
|
|
|
_addDeNetEditBtn(dialogScheduleBtn, dom.deBtn2);
|
|
@@ -142,7 +142,7 @@ function _addDeNetBtnToDialog () {
|
|
|
* 获取左侧twitter按钮
|
|
|
* @private
|
|
|
*/
|
|
|
-function _getSliderTwitterBtn () {
|
|
|
+function _getSliderTwitterBtn() {
|
|
|
dom.tweetBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
|
|
|
dom.tweetBtn.addEventListener('click', function () {
|
|
|
// _addDeNetBtnToDialog();
|
|
@@ -153,13 +153,13 @@ function _getSliderTwitterBtn () {
|
|
|
* 添加deNet按钮
|
|
|
* @private
|
|
|
*/
|
|
|
-function _addDeNetBtn () {
|
|
|
+function _addDeNetBtn() {
|
|
|
setTimeout(() => {
|
|
|
let node = document.querySelector('header[role="banner"]').querySelector('.r-1habvwh');
|
|
|
if (node) {
|
|
|
node.appendChild(dom.deBtn);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
_addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
}, 800)
|
|
@@ -171,7 +171,7 @@ function _addDeNetBtn () {
|
|
|
* @returns {Element}
|
|
|
* @private
|
|
|
*/
|
|
|
-function _getScheduleDom (isDialogInner = false) {
|
|
|
+function _getScheduleDom(isDialogInner = false) {
|
|
|
let scheduleBtn;
|
|
|
if (isDialogInner) {
|
|
|
scheduleBtn = document.querySelector('div[role="dialog"]').querySelector('[data-testid="createPollButton"]');
|
|
@@ -188,7 +188,7 @@ function _getScheduleDom (isDialogInner = false) {
|
|
|
* 插入iframe到页面
|
|
|
* @private
|
|
|
*/
|
|
|
-function _addIframe () {
|
|
|
+function _addIframe() {
|
|
|
// let span = document.createElement('span');
|
|
|
// const shadowRoot = span.attachShadow({mode: 'closed'})
|
|
|
let iframe = document.createElement('iframe');
|
|
@@ -206,7 +206,7 @@ function _addIframe () {
|
|
|
* @returns {string}
|
|
|
* @private
|
|
|
*/
|
|
|
-function _getTwitterArtId () {
|
|
|
+function _getTwitterArtId() {
|
|
|
let firstTwitterArtId = document.querySelector('article[data-testid="tweet"]').querySelector('a[dir="auto"]').getAttribute('href');
|
|
|
return firstTwitterArtId;
|
|
|
}
|
|
@@ -230,7 +230,7 @@ function _deNetBtnClick(port) {
|
|
|
* @param content
|
|
|
* @private
|
|
|
*/
|
|
|
-function _setPublishContent (content) {
|
|
|
+function _setPublishContent(content) {
|
|
|
setTimeout(() => {
|
|
|
document.execCommand("insertText", false, content);
|
|
|
});
|
|
@@ -241,26 +241,26 @@ function _setPublishContent (content) {
|
|
|
* @returns {{deBtn2: HTMLDivElement, deBtn1: HTMLDivElement, deBtn: HTMLSpanElement}}
|
|
|
* @private
|
|
|
*/
|
|
|
-function _createBtnDom (port) {
|
|
|
+function _createBtnDom(port) {
|
|
|
let deBtn = document.createElement('span');
|
|
|
- const shadowRoot = deBtn.attachShadow({mode: 'closed'})
|
|
|
+ const shadowRoot = deBtn.attachShadow({ mode: 'closed' })
|
|
|
const shadowDiv = document.createElement('div');
|
|
|
shadowDiv.innerText = 'DeNet';
|
|
|
shadowDiv.id = 'de-btn';
|
|
|
shadowDiv.style.cssText = 'width:220px;height: 52px;text-align:center;line-height:52px;margin-bottom: 4px;margin-top: 4px;background: linear-gradient(274.8deg, #FF9900 -3.69%, #BD00FF 69.71%, #00F0FF 122.65%);color:#fff;font-size:15px;font-weight:700;border-radius:100px;cursor: pointer;';
|
|
|
shadowRoot.appendChild(shadowDiv);
|
|
|
-
|
|
|
+
|
|
|
const deBtn1 = document.createElement('div');
|
|
|
const smallDeBtnStyle = 'width:30px;height: 30px;text-align:center;line-height:30px;background: linear-gradient(274.8deg, #FF9900 -3.69%, #BD00FF 69.71%, #00F0FF 122.65%);color:#fff;font-size:12px;font-weight:500;border-radius:4px;cursor: pointer;';
|
|
|
deBtn1.innerText = 'De';
|
|
|
deBtn1.id = 'de-btn1';
|
|
|
deBtn1.style.cssText = smallDeBtnStyle;
|
|
|
-
|
|
|
+
|
|
|
const deBtn2 = document.createElement('div');
|
|
|
deBtn2.innerText = 'De';
|
|
|
deBtn2.id = 'de-btn2';
|
|
|
deBtn2.style.cssText = smallDeBtnStyle;
|
|
|
-
|
|
|
+
|
|
|
deBtn.addEventListener('click', () => {
|
|
|
_deNetBtnClick(port);
|
|
|
})
|
|
@@ -276,12 +276,12 @@ function _createBtnDom (port) {
|
|
|
}
|
|
|
|
|
|
/* setInterval(() => {
|
|
|
- let toolBar = document.querySelector('div[data-testid="toolBar"]');
|
|
|
- let innerDeIcon = document.getElementById('de-icon');
|
|
|
- if (toolBar && !innerDeIcon) {
|
|
|
- // let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
- // _addDeNetEditBtn(dialogScheduleBtn, deBtn1);
|
|
|
- }
|
|
|
+ let toolBar = document.querySelector('div[data-testid="toolBar"]');
|
|
|
+ let innerDeIcon = document.getElementById('de-icon');
|
|
|
+ if (toolBar && !innerDeIcon) {
|
|
|
+ // let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
+ // _addDeNetEditBtn(dialogScheduleBtn, deBtn1);
|
|
|
+ }
|
|
|
}, 800) */
|
|
|
|
|
|
function parseDOMRedPacket() {
|
|
@@ -293,7 +293,6 @@ function parseDOMRedPacket() {
|
|
|
// 是否有有红包秘文
|
|
|
}
|
|
|
}
|
|
|
- console.log(_dom)
|
|
|
return _dom
|
|
|
}
|
|
|
|
|
@@ -309,14 +308,18 @@ function replaceDOMRedPacket(_dom) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+let elment = document.documentElement
|
|
|
export function setIframeRedPacket() {
|
|
|
// if(window.location.href != 'https://twitter.com/home'){
|
|
|
// return
|
|
|
// }
|
|
|
- document.addEventListener('scroll', () => {
|
|
|
- // 1.解析推文
|
|
|
- // 2.替换推文
|
|
|
- replaceDOMRedPacket(parseDOMRedPacket())
|
|
|
+ let _current_top = 0
|
|
|
+ document.addEventListener('scroll', (e) => {
|
|
|
+ if ((elment.scrollTop - _current_top) > 500 || (_current_top - elment.scrollTop) > 500) {
|
|
|
+ _current_top = elment.scrollTop
|
|
|
+ // 1.解析推文
|
|
|
+ // 2.替换推文
|
|
|
+ replaceDOMRedPacket(parseDOMRedPacket())
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
-
|