Skip to content

Instantly share code, notes, and snippets.

@mrpapercut
Created July 23, 2019 11:51
Show Gist options
  • Save mrpapercut/c21583dabce5ff16f88c3c0def968833 to your computer and use it in GitHub Desktop.
Save mrpapercut/c21583dabce5ff16f88c3c0def968833 to your computer and use it in GitHub Desktop.
Force Latest Tweets settings for Twitter
// Force latest tweets
let twid_cookie = document.cookie.split(/;\s?/).filter(c => /^twid=/.test(c))[0];
if (twid_cookie) {
let twid = twid_cookie.replace('twid=u%3D', '');
let forceRefresh = false;
// Get DB
let req = window.indexedDB.open('localforage', 2);
req.onerror = ev => {
console.error(req.errorCode);
};
// Connected successfully
req.onsuccess = ev => {
let db = req.result;
let transaction = db.transaction(['keyvaluepairs'], 'readwrite');
let objectStore = transaction.objectStore('keyvaluepairs');
let fetchSetting = objectStore.get(`user:${twid}:rweb.homeTimelineBehavior`);
fetchSetting.onerror = e => {
console.error(e);
}
fetchSetting.onsuccess = e => {
let fetchedSetting = e.target.result;
if (fetchedSetting.useLatest !== true) {
// Set useLatest to true
fetchedSetting.useLatest = true;
// Force page-refresh afterwards
forceRefresh = true;
}
// Updating persistency timestamp
fetchedSetting._lastPersisted = +new Date;
let newSettingObject = objectStore.put(fetchedSetting, `user:${twid}:rweb.homeTimelineBehavior`);
newSettingObject.onsuccess = e => {
if (forceRefresh) document.location.reload(true);
}
}
};
} else {
console.log('Unable to fetch twitter ID from cookie');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment