Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
insin committed Jul 23, 2019
0 parents commit 48a87f11b10eeee24f334fd595ac261f96a7f66f
18 LICENSE
@@ -0,0 +1,18 @@
Copyright (c) 2019, Jonny Buchanan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
# Tweak New Twitter

![](icons/icon128.png)

**Hide retweets, and other UI tweaks for New Twitter**

* [Install Chrome Extension]()
* [Install Firefox Add-on]()
* [Install as a user script](https://github.com/insin/manage-new-twitter/raw/master/manage-new-twitter.user.js) (requires a [user script manager](https://greasyfork.org/en#home-step-1))

## Features

### Hide retweets in your Latest Tweets / Home timeline

### Hide sidebar content (Trends, Who to follow, sidefooter)

## Screenshots

Timeline view with all tweaks enabled (default):

![Screenshot of New Twitter timeline without retweets or sidebar content](screenshots/timeline.png)

Chrome extension options dialog:

![Screenshot of the options UI in Chrome](screenshots/chrome_options.png)

Firefox extension page options:

![Screenshot of the options UI in Firefox](screenshots/firefox_options.png)

## Attribution

Icon adapted from "Twitter free icon" by [Icomoon](https://icomoon.io/) from [www.flaticon.com](https://www.flaticon.com/), [CC 3.0 BY](https://creativecommons.org/licenses/by/3.0/)
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xml:space="preserve"
style="enable-background:new 0 0 533.333 533.333;"
viewBox="0 0 533.333 533.333"
height="533.333px"
width="533.333px"
y="0px"
x="0px"
id="Capa_1"
version="1.1"><metadata
id="metadata41"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs39" /><g
id="g4"><path
id="path2"
d="M444.449,0H88.898C40.006,0,0,40.005,0,88.901v355.533c0,48.926,40.006,88.899,88.898,88.899h355.55 c48.895,0,88.885-39.974,88.885-88.9V88.901C533.333,40.005,493.343,0,444.449,0z M436.486,178.039 c0.171,3.824,0.255,7.671,0.255,11.536c0,117.819-88.134,253.682-249.302,253.682c-49.481,0-95.539-14.767-134.315-40.062 c6.854,0.826,13.829,1.247,20.901,1.247c41.053,0,78.833-14.257,108.819-38.169c-38.341-0.719-70.699-26.498-81.851-61.917 c5.351,1.042,10.839,1.6,16.485,1.6c7.992,0,15.732-1.092,23.083-3.129c-40.083-8.193-70.286-44.228-70.286-87.425 c0-0.376,0-0.75,0.008-1.121c11.812,6.677,25.325,10.687,39.687,11.151c-23.511-15.988-38.98-43.277-38.98-74.212 c0-16.339,4.32-31.655,11.864-44.822c43.215,53.942,107.779,89.438,180.601,93.158c-1.495-6.527-2.27-13.332-2.27-20.32 c0-49.239,39.233-89.156,87.619-89.156c25.204,0,47.98,10.826,63.96,28.155c19.959-3.998,38.711-11.417,55.642-21.637 c-6.543,20.821-20.435,38.293-38.523,49.328c17.723-2.155,34.611-6.948,50.324-14.039 C468.463,149.765,453.607,165.469,436.486,178.039z" /></g><g
id="g6" /><g
id="g8" /><g
id="g10" /><g
id="g12" /><g
id="g14" /><g
id="g16" /><g
id="g18" /><g
id="g20" /><g
id="g22" /><g
id="g24" /><g
id="g26" /><g
id="g28" /><g
id="g30" /><g
id="g32" /><g
id="g34" /><text
id="text3736"
y="166.10159"
x="353.67209"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:53.33333206px;line-height:1.25;font-family:'Comic Sans MS';-inkscape-font-specification:'Comic Sans MS';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
xml:space="preserve"><tspan
y="166.10159"
x="353.67209"
id="tspan3734">X</tspan></text>
</svg>
BIN +2.67 KB icons/icon128.png
Binary file not shown.
BIN +389 Bytes icons/icon16.png
Binary file not shown.
BIN +1023 Bytes icons/icon48.png
Binary file not shown.
BIN +1.31 KB icons/icon64.png
Binary file not shown.
BIN +1.96 KB icons/icon96.png
Binary file not shown.
@@ -0,0 +1,26 @@
{
"manifest_version": 2,
"name": "Tweak New Twitter",
"description": "Hide retweets, and other UI tweaks for New Twitter",
"homepage_url": "https://github.com/insin/tweak-new-twitter/",
"version": "1.0",
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"64": "icons/icon64.png",
"96": "icons/icon96.png",
"128": "icons/icon128.png"
},
"content_scripts": [
{
"matches": [
"https://twitter.com/*"
],
"js": ["./tweak-new-twitter.user.js"]
}
],
"options_ui": {
"page": "options.html"
},
"permissions": ["storage"]
}
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
form {
font-size: 1.25em;
color: #444;
}
hr {
border-style: solid;
border-width: 1px 0 0 0;
border-color: #d7d7d7;
}
label.checkbox input {
margin-left: 0;
vertical-align: middle;
}
label.checkbox span {
vertical-align: middle;
}
section {
padding: .25em .5em;
}
</style>
</head>
<body>
<form>
<section>
<label class="checkbox">
<input type="checkbox" name="showRetweets">
<span>Show retweets in Latest Tweets / Home</span>
</label>
</section>
<hr>
<section>
<label class="checkbox">
<input type="checkbox" name="showSidebarContent">
<span>Show sidebar content</span>
</label>
</section>
<hr>
<section>
<label class="checkbox">
<input type="checkbox" name="enableDebugLogging">
<span>Enable debug logging</span>
</label>
</section>
</form>
<script src="options.js"></script>
</body>
</html>
@@ -0,0 +1,12 @@
chrome.storage.local.get((config) => {
let form = document.querySelector('form')

for (let configItem in config) {
form.elements[configItem].checked = config[configItem] || false
}

form.addEventListener('change', (e) => {
config[e.target.name] = e.target.checked
chrome.storage.local.set(config)
})
})
@@ -0,0 +1,7 @@
{
"scripts": {
"build": "web-ext build",
"lint": "web-ext lint",
"start": "web-ext run"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,156 @@
// ==UserScript==
// @name Tweak New Twitter
// @description Hide retweets, and other UI tweaks for New Twitter
// @namespace https://github.com/insin/tweak-new-twitter/
// @match https://twitter.com/*
// @version 1
// ==/UserScript==

const HOME = 'Home'
const LATEST_TWEETS = 'Latest Tweets'

let config = {}

let currentPage = 'Initialising'

/** MutationObservers active on the current page */
let pageObservers = []

function log(message) {
if (config.enableDebugLogging) {
console.log(`[${currentPage}] ${message}`)
}
}

function s(n) {
return n == 1 ? '' : 's'
}

let $style = document.createElement('style')
$style.dataset.insertedBy = 'tweak-new-twitter'
$style.innerText = `
/* Trends */
div[data-testid="sidebarColumn"] section ,
/* Who to follow */
div[data-testid="sidebarColumn"] aside,
/* Footery stuff in the side bar because infinite scroll */
div[data-testid="sidebarColumn"] nav {
display: none !important;
}`
document.head.appendChild($style)

function observeTitle() {
let $title = document.querySelector('title')

if ($title == null) {
log('waiting for title')
return setTimeout(observeTitle, 1000 / 60 * 3)
}

function processPage(title) {
// Ignore Flash of Uninitialised Title
if (title == 'Twitter') {
return
}

// Assumption: all non-FOUT page title changes are navigation

if (pageObservers.length > 0) {
log(`disconnecting ${pageObservers.length} page observer${s(pageObservers.length)}`)
pageObservers.forEach(observer => observer.disconnect())
pageObservers = []
}

currentPage = title.split(' / ')[0]

log('navigation occurred')

if (currentPage == HOME || currentPage == LATEST_TWEETS) {
if (!config.showRetweets) {
observeTimeline(currentPage)
}
}
if (!config.showSidebarContent) {
hideSidebarContents(currentPage)
}
}

// Watch for page navigation
processPage($title.textContent)
log('observing <title>')
new MutationObserver((mutations) => {
processPage($title.textContent)
}).observe($title, {
characterData: true,
childList: true,
})
}

function observeTimeline(page) {
var $timeline = document.querySelector('div[aria-label^="Timeline"]')
var $firstTweet = document.querySelector('div[data-testid="tweet"]')

if ($timeline == null ||
$timeline.firstElementChild == null ||
$timeline.firstElementChild.firstElementChild == null ||
$firstTweet == null) {
if (currentPage != page) {
return log('stopped waiting for ${page} timeline')
}
return setTimeout(observeTimeline, 1000 / 60 * 5, page)
}

function processTweets() {
let tweets = document.querySelectorAll('div[data-testid="tweet"]')
log(`processing ${tweets.length} tweet${s(tweets.length)}`)
for (let $tweet of tweets) {
let isRetweet = $tweet.previousElementSibling &&
$tweet.previousElementSibling.textContent.includes('Retweeted')
if (isRetweet) {
$tweet.parentNode.parentNode.parentNode.style.display = 'none';
}
}
}

// Watch for new tweets being rendered
log('observing timeline')
processTweets()
let $tweetContainer = $timeline.firstElementChild.firstElementChild
let observer = new MutationObserver(processTweets)
observer.observe($tweetContainer, {
childList: true
})
pageObservers.push(observer)
}

// TODO Wait for responsive breakpoint first if necessary
function hideSidebarContents(page, attempts = 1) {
let $trending = document.querySelector('div[data-testid="sidebarColumn"] section')
if ($trending) {
$trending.parentNode.parentNode.parentNode.style.display = 'none'
}
let $whoToFollow = document.querySelector('div[data-testid="sidebarColumn"] aside')
if ($whoToFollow) {
$whoToFollow.parentNode.parentNode.style.display = 'none'
}

if ($trending == null || $whoToFollow == null) {
if (currentPage != page) {
return log(`stopped waiting for ${page} sidebar`)
}
if (attempts == 10) {
return log(`stopped waiting for sidebar content to hide after ${attempts} attempts`)
}
return setTimeout(hideSidebarContents, 333, page, attempts + 1)
}

log('hid all sidebar content')
}

chrome.storage.local.get((storedConfig) => {
config = storedConfig
if (config.showRetweets && config.showSidebarContent) {
return log('nothing to do!')
}
observeTitle()
})

0 comments on commit 48a87f1

Please sign in to comment.
You can’t perform that action at this time.