Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with x.com #270

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

## Features

Pin Tweet to IPFS is a [web extension](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions) targetting less-technical users who wish to archive Tweets in a verifiable way. It uses [IPFS](https://ipfs.tech/), [WebRecorder](https://webrecorder.net/), and [web3.storage](https://web3.storage/) to achieve this.
Pin Tweet to IPFS is a [web extension](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions) targetting less-technical users who wish to archive Tweets (or "Xeets") in a verifiable way. It uses [IPFS](https://ipfs.tech/), [WebRecorder](https://webrecorder.net/), and [web3.storage](https://web3.storage/) to achieve this.

## How does it work?

Expand All @@ -49,7 +49,7 @@ Basic functionality can be achieved in a bookmarklet

```js
javascript:(function(){
const url = document.location.href.match(/https:\/\/twitter.com\/(\w){1,15}\/status\/(\d)*/)[0];
const url = document.location.href.match(/https:\/\/x.com\/(\w){1,15}\/status\/(\d)*/)[0];
if (url) window.open(`https://webrecorder.github.io/save-tweet-now/#url=${url}&autoupload=1`);
})();
```
Expand Down
4 changes: 2 additions & 2 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import cpy from "cpy";
import { deleteSync } from "del";
import esbuild from "esbuild";

import pkg from "./package.json" assert { type: "json" };
import manifest from "./src/manifest.json" assert { type: "json" };
import pkg from "./package.json" with { type: "json" };
import manifest from "./src/manifest.json" with { type: "json" };

// delete old contents of build/ if exists
deleteSync(["build/**"]);
Expand Down
2 changes: 1 addition & 1 deletion src/Popup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function main() {

chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const currentTab = tabs[0] // there will be only one in this array
const tweetUrlMatch = currentTab.url.match(/https:\/\/twitter.com\/(\w){1,15}\/status\/(\d)*/)
const tweetUrlMatch = currentTab.url.match(/https:\/\/(twitter|x).com\/(\w){1,15}\/status\/(\d)*/)
if (tweetUrlMatch) {
const url = tweetUrlMatch[0]
root.render(<Popup />)
Expand Down
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function init () {
title: 'Pin Tweet to IPFS',
contexts: ['link'],
id: `pin-tweet-to-ipfs-${new Date().toISOString()}`, // unique id to avoid errors
targetUrlPatterns: ['https://twitter.com/*/status/*']
targetUrlPatterns: ['https://x.com/*/status/*']
})

chrome.contextMenus.onClicked.addListener((info) => archiveTweet(info.linkUrl))
Expand Down
15 changes: 9 additions & 6 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function onMutation (mutations) {
chrome.runtime.sendMessage({ url: tweetUrl })
}

const createButton = () => {
const createButton = (small = false) => {
// Icon svg
const parser = new DOMParser()
const logo = parser.parseFromString(iconLogo, 'image/svg+xml')
Expand All @@ -41,7 +41,8 @@ function onMutation (mutations) {

const pinTweetButton = document.createElement('button')
pinTweetButton.appendChild(pinTweetButton.ownerDocument.importNode(logo.documentElement, true))
pinTweetButton.appendChild(label)
if (!small)
pinTweetButton.appendChild(label)
pinTweetButton.style.display = 'flex'
pinTweetButton.style.backgroundColor = 'rgb(104 131 149)'
pinTweetButton.style.color = '#fff'
Expand All @@ -51,9 +52,10 @@ function onMutation (mutations) {
pinTweetButton.style.letterSpacing = '0.5px'
pinTweetButton.style.padding = '5px 10px'
pinTweetButton.style.cursor = 'pointer'
pinTweetButton.style.minWidth = '165px'
pinTweetButton.style.minWidth = small ? '' : '165px'
pinTweetButton.addEventListener('click', (e) => getTweetUrl(e))
pinTweetButton.id = `pin-tweet-${new Date().toISOString()}`
pinTweetButton.title = 'Pin Tweet to IPFS'
return pinTweetButton
}

Expand All @@ -67,7 +69,8 @@ function onMutation (mutations) {
.apply(node.querySelectorAll("[role='group']"))
.filter(
(node) =>
!node.hasAttribute('aria-label') &&
node.ariaLabel &&
node.ariaLabel.includes('view') &&
node.id &&
!found.includes(node)
)
Expand All @@ -77,7 +80,7 @@ function onMutation (mutations) {
.apply(node.querySelectorAll('[aria-label]'))
.filter(
(node) =>
node.ariaLabel.includes('eplies') &&
node.ariaLabel.includes('view') &&
node.id &&
!found.includes(node)
)
Expand All @@ -88,6 +91,6 @@ function onMutation (mutations) {

found.forEach((n) => {
if (n.querySelector("[id^='pin-tweet']")) return // return early if there is already a button appended
n.appendChild(createButton())
n.appendChild(createButton(n.offsetWidth < 165 * 2))
})
}
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"content_scripts": [
{
"matches": [
"https://*.twitter.com/*",
"https://*.x.com/*",
"https://x.com/*",
"https://webrecorder.github.io/save-tweet-now/"
],
"js": ["content.js"]
Expand Down