feat: avoid loop

This commit is contained in:
Florian Hönicke
2023-05-15 16:00:54 +02:00
parent f1fcd1adcf
commit 5351fa5f12
3 changed files with 92 additions and 6 deletions

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 512 512" xml:space="preserve">
<g>
<g>
<g>
<path d="M349.679,445.252c-0.666-15.437-3.755-52.685-18.313-74.522c-2.62-3.917-7.919-4.992-11.836-2.364
c-3.917,2.611-4.975,7.91-2.364,11.827c11.494,17.254,14.532,48.58,15.343,63.599c-4.565,0.162-8.243,3.866-8.243,8.474
c0,4.71,3.823,8.533,8.533,8.533h8.533c4.659,0,8.388,3.661,8.491,8.328c0.009,0.222,0.017,0.435,0.043,0.649v25.156h-34.133
v-25.6c0-0.256-0.026-0.606-0.051-0.956c-0.393-10.539-7.313-19.448-16.742-22.98c0.58-9.583,2.389-28.348,8.004-50.799
c1.143-4.574-1.638-9.207-6.204-10.342c-4.548-1.135-9.207,1.63-10.351,6.204c-5.845,23.381-7.799,42.743-8.457,53.274h-8.866
c-2.995,0-5.845,0.614-8.533,1.579V409.6c0-4.719-3.823-8.533-8.533-8.533c-4.71,0-8.533,3.814-8.533,8.533v35.712
c-2.688-0.964-5.538-1.579-8.533-1.579h-8.875c-0.648-10.53-2.603-29.892-8.448-53.274c-1.143-4.574-5.777-7.339-10.351-6.204
c-4.565,1.135-7.347,5.768-6.204,10.342c5.606,22.451,7.415,41.216,8.004,50.799c-9.429,3.533-16.35,12.442-16.742,22.98
c-0.034,0.35-0.051,0.7-0.051,0.956v25.6h-34.133v-25.156c0.017-0.213,0.034-0.427,0.034-0.649
c0.111-4.668,3.84-8.328,8.499-8.328h8.533c4.71,0,8.533-3.823,8.533-8.533c0-4.608-3.669-8.312-8.243-8.474
c0.802-15.019,3.84-46.345,15.343-63.599c2.611-3.917,1.553-9.216-2.364-11.827c-3.925-2.628-9.225-1.553-11.836,2.364
c-14.558,21.837-17.655,59.085-18.313,74.522c-9.66,3.413-16.802,12.425-17.203,23.125c-0.034,0.35-0.051,0.7-0.051,0.956v34.133
c0,4.71,3.823,8.533,8.533,8.533h51.2H256h51.2h51.2c4.71,0,8.533-3.823,8.533-8.533v-34.133c0-0.256-0.026-0.606-0.051-0.956
C366.481,457.677,359.33,448.666,349.679,445.252z M247.467,477.867v17.067h-34.133v-25.156c0.017-0.213,0.034-0.427,0.034-0.649
c0.111-4.668,3.84-8.328,8.499-8.328h17.067c4.659,0,8.388,3.661,8.491,8.328c0.009,0.222,0.017,0.435,0.043,0.649V477.867z
M298.667,494.933h-34.133v-17.067v-8.09c0.017-0.213,0.034-0.427,0.034-0.649c0.111-4.668,3.84-8.328,8.499-8.328h17.067
c4.659,0,8.388,3.661,8.491,8.328c0.009,0.222,0.017,0.435,0.043,0.649V494.933z"/>
<path d="M281.6,341.333c4.71,0,8.533-3.823,8.533-8.533v-8.533c0-4.719-3.823-8.533-8.533-8.533s-8.533,3.814-8.533,8.533v8.533
C273.067,337.51,276.89,341.333,281.6,341.333z"/>
<path d="M102.4,25.6c0,4.71,3.823,8.533,8.533,8.533s8.533-3.823,8.533-8.533c4.71,0,8.533-3.823,8.533-8.533
c0-4.719-3.823-8.533-8.533-8.533c0-4.719-3.823-8.533-8.533-8.533S102.4,3.814,102.4,8.533c-4.71,0-8.533,3.814-8.533,8.533
C93.867,21.777,97.69,25.6,102.4,25.6z"/>
<path d="M42.667,110.933h-8.533V102.4c0-4.719-3.823-8.533-8.533-8.533c-4.71,0-8.533,3.814-8.533,8.533v8.533H8.533
c-4.71,0-8.533,3.814-8.533,8.533C0,124.177,3.823,128,8.533,128h8.533v8.533c0,4.71,3.823,8.533,8.533,8.533
c4.71,0,8.533-3.823,8.533-8.533V128h8.533c4.71,0,8.533-3.823,8.533-8.533C51.2,114.748,47.377,110.933,42.667,110.933z"/>
<path d="M102.4,204.8c0-4.719-3.823-8.533-8.533-8.533c-4.71,0-8.533,3.814-8.533,8.533c-4.71,0-8.533,3.814-8.533,8.533
c0,4.71,3.823,8.533,8.533,8.533c0,4.71,3.823,8.533,8.533,8.533c4.71,0,8.533-3.823,8.533-8.533c4.71,0,8.533-3.823,8.533-8.533
C110.933,208.614,107.11,204.8,102.4,204.8z"/>
<path d="M221.867,226.133c0-7.057-5.743-12.8-12.8-12.8c-7.057,0-12.8,5.743-12.8,12.8s5.743,12.8,12.8,12.8
C216.124,238.933,221.867,233.19,221.867,226.133z"/>
<path d="M401.067,136.533c-35.26,0-59.11,8.695-60.109,9.062c-0.589,0.222-1.033,0.623-1.545,0.956
c-13.559-8.439-31.701-17.758-51.721-22.972c-2.918-28.433-9.335-70.195-23.518-117.495C263.091,2.466,259.763,0,256,0
c-3.772,0-7.091,2.466-8.175,6.084c-14.191,47.3-20.608,89.062-23.518,117.495c-20.07,5.231-38.255,14.592-51.84,23.057
c-0.546-0.358-1.024-0.794-1.656-1.033c-0.99-0.367-24.602-9.071-59.878-9.071c-4.71,0-8.533,3.814-8.533,8.533
c0,29.065,10.906,47.369,34.21,57.139c1.212,49.289,17.186,81.792,17.886,83.209c1.502,2.995,4.514,4.719,7.646,4.719
c1.28,0,2.586-0.29,3.806-0.905c4.215-2.108,5.922-7.228,3.814-11.452c-0.162-0.316-16.162-32.888-16.162-81.51
c0-3.678-2.355-6.938-5.837-8.098c-17.749-5.914-26.052-15.863-27.895-34.364c15.095,0.691,27.128,3.004,34.995,4.932
c-4.045,3.081-6.477,5.163-6.844,5.478c-3.567,3.081-3.951,8.465-0.87,12.032c1.681,1.946,4.062,2.944,6.451,2.944
c1.98,0,3.968-0.683,5.581-2.074c0.307-0.265,28.689-24.457,63.548-35.345c-0.836,12.194-0.862,19.465-0.862,20.361
c0,2.355,0.956,4.489,2.5,6.033c0.111,0.111,0.282,0.162,0.401,0.273c0.691,0.614,1.442,1.186,2.304,1.553
c0.512,0.213,1.101,0.222,1.647,0.333c0.563,0.111,1.084,0.341,1.673,0.341h0.009h51.2c0.597,0,1.118-0.23,1.681-0.341
c0.546-0.111,1.135-0.119,1.647-0.333c0.862-0.367,1.604-0.939,2.304-1.553c0.12-0.111,0.282-0.162,0.401-0.273
c1.545-1.544,2.5-3.678,2.5-6.033c0-0.896-0.034-8.166-0.862-20.361c34.884,10.88,63.232,35.072,63.539,35.345
c1.621,1.391,3.601,2.074,5.581,2.074c2.389,0,4.77-0.99,6.46-2.944c3.081-3.558,2.697-8.943-0.862-12.032
c-0.367-0.316-2.816-2.415-6.886-5.513c7.936-1.92,20.002-4.207,35.029-4.898c-1.835,18.509-10.146,28.45-27.904,34.364
c-3.482,1.161-5.828,4.42-5.828,8.098c0,48.35-16.017,81.203-16.171,81.527c-2.091,4.216-0.375,9.336,3.84,11.435
c1.22,0.614,2.517,0.896,3.797,0.896c3.132,0,6.135-1.724,7.629-4.71c0.708-1.417,16.674-33.92,17.894-83.209
c23.305-9.771,34.21-28.075,34.21-57.139C409.6,140.348,405.777,136.533,401.067,136.533z M256,41.037
c3.874,15.812,6.835,30.686,9.148,44.297h-18.295C249.165,71.723,252.126,56.849,256,41.037z M244.181,102.4h23.637
c0.862,6.05,1.596,11.776,2.193,17.067h-28.023C242.586,114.176,243.319,108.45,244.181,102.4z M239.198,153.6
c0.188-4.258,0.529-10.018,1.109-17.067h31.386c0.58,7.049,0.922,12.809,1.109,17.067H239.198z"/>
<path d="M469.333,221.867H460.8v-8.533c0-4.719-3.823-8.533-8.533-8.533c-4.71,0-8.533,3.814-8.533,8.533v8.533H435.2
c-4.71,0-8.533,3.814-8.533,8.533c0,4.71,3.823,8.533,8.533,8.533h8.533v8.533c0,4.71,3.823,8.533,8.533,8.533
c4.71,0,8.533-3.823,8.533-8.533v-8.533h8.533c4.71,0,8.533-3.823,8.533-8.533C477.867,225.681,474.044,221.867,469.333,221.867z
"/>
<path d="M503.467,34.133c0-4.719-3.823-8.533-8.533-8.533s-8.533,3.814-8.533,8.533c-4.71,0-8.533,3.814-8.533,8.533
c0,4.71,3.823,8.533,8.533,8.533c0,4.71,3.823,8.533,8.533,8.533s8.533-3.823,8.533-8.533c4.71,0,8.533-3.823,8.533-8.533
C512,37.948,508.177,34.133,503.467,34.133z"/>
<path d="M171.102,304.495c-4.233,12.698-0.7,28.245,9.685,42.658C193.63,364.971,220.126,384,256,384
c35.866,0,62.37-19.029,75.204-36.847c10.394-14.413,13.926-29.961,9.694-42.658c-0.606-1.801-1.783-3.345-3.362-4.395
c-1.135-0.759-28.365-18.5-81.536-18.5s-80.401,17.741-81.536,18.5C172.885,301.15,171.699,302.694,171.102,304.495z
M186.615,312.789c7.569-3.934,30.839-14.123,69.385-14.123c38.571,0,61.858,10.206,69.376,14.123
c1.007,6.98-1.869,15.855-8.013,24.388c-10.368,14.379-31.932,29.756-61.363,29.756s-50.995-15.377-61.363-29.756
C188.484,328.644,185.617,319.778,186.615,312.789z"/>
<path d="M315.733,226.133c0-7.057-5.743-12.8-12.8-12.8s-12.8,5.743-12.8,12.8s5.743,12.8,12.8,12.8
S315.733,233.19,315.733,226.133z"/>
<path d="M230.4,341.333c4.71,0,8.533-3.823,8.533-8.533v-8.533c0-4.719-3.823-8.533-8.533-8.533c-4.71,0-8.533,3.814-8.533,8.533
v8.533C221.867,337.51,225.69,341.333,230.4,341.333z"/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -7,6 +7,7 @@ chrome.storage.sync.get({
}, function(items) {
openai_api_key = items.openai_api_key;
});
let observer = new MutationObserver((mutations) => {
console.log('Twitter Rewrite: DOM mutation detected');
// For each mutation
@@ -15,7 +16,7 @@ let observer = new MutationObserver((mutations) => {
if (mutation.addedNodes) {
mutation.addedNodes.forEach((node) => {
// If the added node (or its descendants) contains a tweet
let tweets = node.querySelectorAll('[data-testid="tweetText"]');
let tweets = node.querySelectorAll('[data-testid="tweet"]');
tweets.forEach((tweet) => {
// If the tweet doesn't already have a modify button
if (!tweet.querySelector('.modify-button')) {
@@ -32,8 +33,9 @@ let observer = new MutationObserver((mutations) => {
// Add event listener for button click
button.addEventListener('click', function() {
let thisButton = this;
// Send tweet to API
let originalTweet = tweet.innerText;
let originalTweet = tweet.querySelector('[data-testid="tweetText"]').innerText;
this.disabled = true;
this.innerText = 'Loading...';
fetch('https://gptdeploy-61694dd6a3.wolf.jina.ai/post', {
@@ -60,12 +62,16 @@ let observer = new MutationObserver((mutations) => {
let newTweet = document.createElement('span');
newTweet.innerHTML = rainbowTweet;
// Replace the old text node with the new element node
tweet.replaceWith(newTweet);
tweet.querySelector('[data-testid="tweetText"]').replaceWith(newTweet);
// Remove the button
thisButton.remove();
});
});
// Inject button into tweet
tweet.appendChild(button);
// Find the actions container and inject the button into it
let actionGroups = tweet.querySelectorAll('div[role="group"]');
let actionsContainer = actionGroups[actionGroups.length - 1];
actionsContainer.appendChild(button);
}
});
});

View File

@@ -1,5 +1,6 @@
.modify-button {
background-color: #00acee; /* Twitter Blue */
/* transparent */
background-color: #00000000;
color: white;
border: none;
padding: 5px 10px;