Skip to content

Instantly share code, notes, and snippets.

@hinaloe
Forked from if1live/Twitter Cramming.user.js
Last active September 28, 2017 05:35
Show Gist options
  • Save hinaloe/c2381b1370371f5d9a4bb2be190f9c66 to your computer and use it in GitHub Desktop.
Save hinaloe/c2381b1370371f5d9a4bb2be190f9c66 to your computer and use it in GitHub Desktop.
Force enable cramming (280 character tweets) on Twitter. NOTE: Stops working when you switch pages, refresh to fix. https://twitter.com/Prof9/status/912859110776950784
// ==UserScript==
// @name Twitter Cramming
// @description Force enable cramming (280 character tweets) on Twitter
// @author Prof. 9
// @version 0.1
// @match https://twitter.com/*
// @run-at document-idle
// @namespace prof9.twittercramming
// ==/UserScript==
var initDataInput = document.getElementById('init-data');
var initData = JSON.parse(initDataInput.value);
initData.deciders.cramming_feature_enabled = true;
initData.deciders.cramming_ui_enabled = true;
initDataInput.value = JSON.stringify(initData);
// for CJK and etc
function getTwitterTextOptions() {
var tweetForm = document.querySelector('form.tweet-form');
var keys = Object.keys(tweetForm);
for(var i = 0 ; i < keys.length ; i++) {
if(keys[i].startsWith('jQuery')) {
var jqc = tweetForm[keys[i]];
return jqc.events.uiTextChanged[0].handler.context.attr.twitterTextOptions;
}
}
return null;
}
function modifyTextWeight() {
var opt = getTwitterTextOptions();
//alert(JSON.stringify(opt));
if(opt) {
opt.ranges[1].weight = 100;
opt.default_weight = 100;
return true;
}
return false;
}
document.onreadystatechange = function() {
function check() {
var success = modifyTextWeight();
if(!success) {
setTimeout(check, 100);
}
}
check();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment