// ==UserScript== // @name Twetch HQ Image Upload, Better GIFs, Lower Twetch Fees, Media Player & More (Firefox Only) // @namespace https://bsv.sh/ // @version 13.2.2 // @description Grants image upload access on Twetch; Fix Twetch bugs with HQ images; Animated images for sizes smaller than 98.8kB; SVG; Adjustable Twetch costs; Non-dynamic page navigation; Media Player; userIDs & Collapse Twetch. (use at your own risk) // @author Klimenos // @updateURL https://bsv.sh/Twetch/Twetch_Image_Upload.user.js // @include https://*.twetch.app/* // @include https://twetch.app/* // @require https://code.jquery.com/jquery-latest.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_xmlhttpRequest // @run-at document-start // ==/UserScript== // INSTRUCTIONS: // 0. Download Firefox Developer Edition: https://www.mozilla.org/en-US/firefox/developer/ // 1. Install the Tampermonkey extension for Firefox: https://www.tampermonkey.net/ // 2. Visit this page to install the Twetch Image Upload userscript: https://bsv.sh/Twetch/Twetch_Image_Upload.user.js // 3. You can choose to deactivate automatic updates by removing the @updateURL line above. // 4. Just use the Twetch upload icons normally. If Money Button gives you an error, try reducing the length of your Twetch text or the weight of your image. // 5. Adjust the settings below. // 6. Enjoy and report bugs/issues/feedback to me. // SETTINGS (you can customise them): var force_activate_image_upload = true; // Set to true or false to force the activation of the Twetch image upload button (default: true = image upload activated). var adjust_costs = false; // Set to true or false to adjust Twetch prices (default: false = custom costs not enabled). var twetch_fee_cost = 0.001; // Cost of a Twetch fee in USD (current default Twetch currency), don't set this value below 0.001 var like_cost = 0.004; // Cost of a like in USD (current default Twetch currency), don't set this value below 0.004 var reply_cost = 0.002; // Cost of a reply in USD (current default Twetch currency), don't set this value below 0.002 var reply_branch_cost = 0.001; // Cost of a reply branch in USD (current default Twetch currency), don't set this value below 0.001 var mention_cost = 0.001; // Cost of a mention in USD (current default Twetch currency), don't set this value below 0.001 var feature_cost = 0.001; // Cost of a feature in USD (current default Twetch currency), don't set this value below 0.001 var activate_darkMode = false; // Set to true or false to force the activation of Dark Mode (default: false = Dark Mode not enforced). var activate_userID_with_Thumbnail = true; // Set to true or false to activate Twetch userID with thumbnails (default: true = Twetch userID displayed with thumbnails). var activate_collapse_Twetch = true; // Set to true or false to bundle Twetches from the same user (default: true = Twetch collapse activated). var muted_twetchers = ["1494", "466", "1711"]; // If you use Klimenos' Mute Twetch Users, ensure the list is the same. Add XXX Twetch user IDs (https://twetch.app/u/XXX) to the list (default: "1494", "466", "1711" = Twetch users /u/1494, /u/466 and /u/1711 muted). var non_dynamic_pagenav = true; // Set to true or false to activate non-dynamic page navigation (default: true = non-dynamic page navigation enabled). This fixes Twetch cache issues and userID/Collapse/Mute bugs, strongly advised to leave it true. // TEMPORARY DISABLED DUE TO CODE CHANGE var image_hacks = false; // Set to true or false to activate image upload hacks (default: true = image hacks enabled). var coloured_image_icon = false; // Set to true or false to have a coloured image upload button (default: true = image upload icon is coloured). var max_image_width_and_height_jpeg = 700; // Default max image width chosen when JPEG images are compressed (default: 700 pixels), don't crank it too high (remember the OP_RETURN size limit). var image_quality_redim_jpeg = 40; // Define the threshold from where the JPEG image dimensions should start to be reduced (default: 40 percent). var image_conversion_threshold = 98800; // Set the value in bytes of the threshold for image conversion/size reduction trigger (default: 98800 = 98.8kB), don't crank it above 98.8kB (remember the OP_RETURN size limit). var activate_svg = false; // Set to true or false to activate SVG (default: true = SVG button is displayed). var svg_width = '508'; // Set the width of your SVG (default: 508 = 508 pixels). var svg_height = '508'; // Set the height of your SVG (default: 508 = 508 pixels). // DEPRECATED SETTINGS var disable_twetch_fees = false; // Set to true or false to disable twetch fees (default: false = fees enabled). // No longer works. The loophole has been fixed by Twetch, but you can now lower the fees through twetch_fee_cost. var follow_cost = null; // Cost of a follow in USD (current default Twetch currency), don't set this value below 0.001 // Looks like this has been fixed by Twetch... var image_quality_redim_png = 95; // Define the threshold from where the PNG image dimensions should start to be reduced (default: 95 percent). // Not used anymore since we automatically convert big PNG images to JPEG var image_quality_redim_other = 50; // Define the threshold from where generic image dimensions should start to be reduced (default: 50 percent). // Not used anymore since we automatically convert big PNG images to JPEG var max_image_width_and_height_png = 508; // Default max image width chosen when PNG images are compressed (default: 508 pixels), don't crank it above 508px (Twetch PNG converter isn't great). // Not used anymore since we automatically convert big PNG images to JPEG var activate_mediaPlayer = false; // Set to true or false to activate the media player for audio and video files (default: false = media player disabled). // Native implementation available // NOTES: // 0. If image_hacks is true, you will notice the userscript is active when the upload image icon has a rainbow changing colour. // 1. JPEG and PNG images heavier than 98.8kB are resized to 'max_image_width_and_height_*' (unless their width is smaller), compressed and converted to JPEG or Static PNG (B:// OP_RETURN size limit). Images that fit 98.8kB will be left untouched. It's often best to resize your own images if you wish to ensure high quality. // 2. Optimise your GIFs with https://ezgif.com/. More info: https://twetch.app/t/c45696a8d9e4166b2706ee076a5cf3d7fc995c034d773ce755e0ec18fe69de34#e1a387c711003ce0735739e50f01b5bb0b65fbd6a845e03bf348db2bffc14797 // 3. This userscript is currently only supported on recent versions of Firefox. // 4. Unlimited chars has been disabled. Twetch fixed the loophole. Unlimited characters isn't really unlimited. If Money Button gives you an error, it means your Twetch is bigger than the allowed OP_RETURN data size. // 5. Disabling Twetch fees has been disabled by default. If you want to support Twetch devs, don't disable it! // 6. New updates will overwrite your settings. // 7. GIF is now supported by default on Twetch. // 8. You can now upload the following additonal mimeTypes: "image/tiff", "image/svg+xml", "image/bmp", "image/webp", "video/mp4". Remember not all web browsers read mp4 (only Safari & iOS) and WebP (most but Safari & iOS)! // 9. Re-upload PNG files to compress them in higher quality! (That works because the first pass calculates the best width for the image but sacrifices quality at the same time. The second pass starts again with 100% quality but reduced size.) // --- DO NOT TOUCH THE REST OF THIS SCRIPT --- // // Warn users the script isn't compatible for their Web Browser when that's the case var ua = window.navigator.userAgent; var ua_ff = ua.match(/Firefox\/.*$/g); if (ua_ff[0].match(/^Firefox/g) == "Firefox") { var ua_ff_v = ua_ff[0].match(/(\d)*\.(\d)*/g); if (ua_ff_v < "68") { alert("Sorry, your Firefox version is too old and hasn't been tested with Klimenos' Twetch HQ Image Upload tweak.\n\nPlease install a more recent version of Firefox."); } } else { alert("Sorry, your Web Browser is not Compatible with Klimenos' Twetch HQ Image Upload tweak.\n\nPlease install Firefox Developers web browser at https://www.mozilla.org/en-US/firefox/developer/."); } // Check if replace occured function replace_occured(t, t_, ok, tag, tag_num, force_ok){ if (t === t_) { if (force_ok == true) { ok[tag] = true; console.log(tag+" patch"+tag_num+" FORCED SUCCESS!"); } else{ ok[tag] = false; console.log(tag+" patch"+tag_num+" FAILED!"); } } else { ok[tag] = true; console.log(tag+" patch"+tag_num+" SUCCESS!"); } return ok[tag]; } // Update HUD item with value function update_hud(tag, value){ document.getElementById(tag).innerHTML = ''+value; } // Find and replace + return status function find_replace(find, replace, a_text, force_ok){ a_text.new_text = a_text.text.replace(find, replace); if (ok[a_text.tag] && replace_occured(a_text.new_text, a_text.text, a_text.ok, a_text.tag, ++a_text.tag_num, force_ok)){ a_text.text = a_text.new_text; a_text.final = true; if (force_ok) { update_hud(a_text.tag, hud_strings.force_success); // Update HUD update_hud(a_text.tag+'_led', hud_led.force_success); // Update HUD } else { update_hud(a_text.tag, hud_strings.success); // Update HUD update_hud(a_text.tag+'_led', hud_led.success); // Update HUD } return true; } a_text.final = false; update_hud(a_text.tag, hud_strings.failed); // Update HUD update_hud(a_text.tag+'_led', hud_led.failed); // Update HUD return false; } // Apply the patched text function apply_patch(a_text){ console.log(a_text.tag+': '+a_text.final); if (a_text.final == true) { return a_text.text; } else { return a_text.ori_text; update_hud(a_text.tag, hud_strings.failed); // Update HUD update_hud(a_text.tag+'_led', hud_led.failed); // Update HUD } } // Reset a_text function reset_a_text (a_text, text, tag){ a_text.tag = tag; a_text.tag_num = 0; a_text.ori_text = text; a_text.text = text; a_text.final = false; } // Construct SVG for unlimited chars //var Klimenos_activate_svg_svg_begin = ''; var Klimenos_activate_svg_svg_constructor = '"data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(\''+Klimenos_activate_svg_svg_begin+'\'+(window.Klimenos_activate_svg_hack_image_textarea).replace(/[\\n\\r]/g, "
")+\''+Klimenos_activate_svg_svg_end+'\')))';
// Function for unlimited chars
var Klimenos_activate_svg_function = 'if (window.KlimenosSVGActivator == true && document.getElementById("image-upload-input") != null && document.getElementById("compose-input") != null && document.getElementById("compose-input").value !== "" && document.getElementById("compose-input").value != window.Klimenos_activate_svg_hack_image_textarea){ console.log("value: "+document.getElementById("compose-input").value); console.log("image-upload-input FOUND!"); var element = document.getElementById("image-upload-input"); console.log("element: "+element); window.Klimenos_activate_svg_hack_image_textarea = document.getElementById("compose-input").value; window.Klimenos_activate_svg_hack_image = '+Klimenos_activate_svg_svg_constructor+'; var element = document.getElementById("image-upload-input"); var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", true, true); element.dispatchEvent(evt); };';
// Vars for Resillience
var new_text, tag, tag_num, cur_tag;
//var ok_force_activate_image_upload = true, ok_coloured_image_icon = true, ok_activate_svg = true;
var ok = {force_activate_image_upload_updateCompose: true, coloured_image_icon_updateCompose: true, image_hacks_updateCompose: true, activate_svg_updateCompose: true, disable_twetch_fees_updateCompose: true, adjust_costs_updateCompose: true, activate_darkMode_updateCompose: true, disable_twetch_fees_updateCommon: true, adjust_costs_updateCommon: true, activate_darkMode_updateCommon: true, activate_darkMode_updateApp:true, activate_darkMode_updateSettings: true, adjust_costs_updateSettings: true, activate_userID_with_Thumbnail: true, activate_collapse_Twetch: true, non_dynamic_pagenav_updateIndex: true, activate_mediaPlayer: true};
var a_text = {ori_text:null, text: null, next_text: null, tag: null, tag_num: null, ok: ok, final: false};
const force_ok = true;
// Var for image count
var unique_img_count = 0;
function updateCompose(text) {
//console.log('replacing whatever in compose');
cur_tag = 'force_activate_image_upload_updateCompose';
if (force_activate_image_upload){
// FORCE IMAGE UPLOAD ACTIVATION
reset_a_text(a_text, text, cur_tag);
find_replace("this.props.auth.me.hasImageUpload", "true", a_text); // Enable Twetch image upload for all
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'coloured_image_icon_updateCompose';
if (coloured_image_icon){
// SHOWS THAT IMAGE HACK IS ACTIVE
reset_a_text(a_text, text, cur_tag);
find_replace(',stroke:"#0094FF"})', ',stroke:"#00FF6A"}, w("animate", {attributeName: "stroke", begin: "0s", dur: "10s", repeatCount: "indefinite", values: "#ff0000; #ff0500; #ff0a00; #ff0f00; #ff1400; #ff1800; #ff1d00; #ff2200; #ff2700; #ff2c00; #ff3100; #ff3600; #ff3b00; #ff4000; #ff4400; #ff4900; #ff4e00; #ff5300; #ff5800; #ff5d00; #ff6200; #ff6700; #ff6b00; #ff7000; #ff7500; #ff7a00; #ff7f00; #ff8400; #ff8900; #ff8e00; #ff9300; #ff9800; #ff9d00; #ffa100; #ffa600; #ffab00; #ffb000; #ffb500; #ffba00; #ffbf00; #ffc400; #ffc900; #ffce00; #ffd300; #ffd800; #ffdd00; #ffe100; #ffe600; #ffeb00; #fff000; #fff500; #fffa00; #ffff00; #f5ff00; #ebff00; #e2ff00; #d8ff00; #ceff00; #c4ff00; #baff00; #b1ff00; #a7ff00; #9dff00; #93ff00; #89ff00; #7fff00; #76ff00; #6cff00; #62ff00; #58ff00; #4eff00; #45ff00; #3bff00; #31ff00; #27ff00; #1dff00; #14ff00; #0aff00; #00ff00; #00ff0a; #00ff14; #00ff1d; #00ff27; #00ff31; #00ff3b; #00ff45; #00ff4e; #00ff58; #00ff62; #00ff6c; #00ff76; #00ff80; #00ff89; #00ff93; #00ff9d; #00ffa7; #00ffb1; #00ffba; #00ffc4; #00ffce; #00ffd8; #00ffe2; #00ffeb; #00fff5; #00ffff; #00f5ff; #00ebff; #00e2ff; #00d8ff; #00ceff; #00c4ff; #00baff; #00b1ff; #00a7ff; #009dff; #0093ff; #0089ff; #007fff; #0076ff; #006cff; #0062ff; #0058ff; #004eff; #0045ff; #003bff; #0031ff; #0027ff; #001dff; #0014ff; #000aff; #0000ff; #0500ff; #0b00ff; #1000ff; #1500ff; #1b00ff; #2000ff; #2500ff; #2b00ff; #3000ff; #3500ff; #3b00ff; #4000ff; #4500ff; #4b00ff; #5000ff; #5600ff; #5b00ff; #6000ff; #6600ff; #6b00ff; #7000ff; #7600ff; #7b00ff; #8000ff; #8600ff; #8b00ff; #8600ff; #8000ff; #7b00ff; #7600ff; #7000ff; #6b00ff; #6600ff; #6000ff; #5b00ff; #5600ff; #5000ff; #4b00ff; #4500ff; #4000ff; #3b00ff; #3500ff; #3000ff; #2b00ff; #2500ff; #2000ff; #1b00ff; #1500ff; #1000ff; #0b00ff; #0500ff; #0000ff; #000aff; #0014ff; #001dff; #0027ff; #0031ff; #003bff; #0045ff; #004eff; #0058ff; #0062ff; #006cff; #0076ff; #007fff; #0089ff; #0093ff; #009dff; #00a7ff; #00b1ff; #00baff; #00c4ff; #00ceff; #00d8ff; #00e2ff; #00ebff; #00f5ff; #00ffff; #00fff5; #00ffeb; #00ffe2; #00ffd8; #00ffce; #00ffc4; #00ffba; #00ffb1; #00ffa7; #00ff9d; #00ff93; #00ff89; #00ff80; #00ff76; #00ff6c; #00ff62; #00ff58; #00ff4e; #00ff45; #00ff3b; #00ff31; #00ff27; #00ff1d; #00ff14; #00ff0a; #00ff00; #0aff00; #14ff00; #1dff00; #27ff00; #31ff00; #3bff00; #45ff00; #4eff00; #58ff00; #62ff00; #6cff00; #76ff00; #7fff00; #89ff00; #93ff00; #9dff00; #a7ff00; #b1ff00; #baff00; #c4ff00; #ceff00; #d8ff00; #e2ff00; #ebff00; #f5ff00; #ffff00; #fffa00; #fff500; #fff000; #ffeb00; #ffe600; #ffe100; #ffdd00; #ffd800; #ffd300; #ffce00; #ffc900; #ffc400; #ffbf00; #ffba00; #ffb500; #ffb000; #ffab00; #ffa600; #ffa100; #ff9d00; #ff9800; #ff9300; #ff8e00; #ff8900; #ff8400; #ff7f00; #ff7a00; #ff7500; #ff7000; #ff6b00; #ff6700; #ff6200; #ff5d00; #ff5800; #ff5300; #ff4e00; #ff4900; #ff4400; #ff4000; #ff3b00; #ff3600; #ff3100; #ff2c00; #ff2700; #ff2200; #ff1d00; #ff1800; #ff1400; #ff0f00; #ff0a00; #ff0500;"}))', a_text);
find_replace(',stroke:"#0094FF",color:"transparent"})', ',stroke:"#00FF6A",color: "transparent"}, w("animate", {attributeName: "stroke", begin: "0s", dur: "10s", repeatCount: "indefinite", values: "#ff0000; #ff0500; #ff0a00; #ff0f00; #ff1400; #ff1800; #ff1d00; #ff2200; #ff2700; #ff2c00; #ff3100; #ff3600; #ff3b00; #ff4000; #ff4400; #ff4900; #ff4e00; #ff5300; #ff5800; #ff5d00; #ff6200; #ff6700; #ff6b00; #ff7000; #ff7500; #ff7a00; #ff7f00; #ff8400; #ff8900; #ff8e00; #ff9300; #ff9800; #ff9d00; #ffa100; #ffa600; #ffab00; #ffb000; #ffb500; #ffba00; #ffbf00; #ffc400; #ffc900; #ffce00; #ffd300; #ffd800; #ffdd00; #ffe100; #ffe600; #ffeb00; #fff000; #fff500; #fffa00; #ffff00; #f5ff00; #ebff00; #e2ff00; #d8ff00; #ceff00; #c4ff00; #baff00; #b1ff00; #a7ff00; #9dff00; #93ff00; #89ff00; #7fff00; #76ff00; #6cff00; #62ff00; #58ff00; #4eff00; #45ff00; #3bff00; #31ff00; #27ff00; #1dff00; #14ff00; #0aff00; #00ff00; #00ff0a; #00ff14; #00ff1d; #00ff27; #00ff31; #00ff3b; #00ff45; #00ff4e; #00ff58; #00ff62; #00ff6c; #00ff76; #00ff80; #00ff89; #00ff93; #00ff9d; #00ffa7; #00ffb1; #00ffba; #00ffc4; #00ffce; #00ffd8; #00ffe2; #00ffeb; #00fff5; #00ffff; #00f5ff; #00ebff; #00e2ff; #00d8ff; #00ceff; #00c4ff; #00baff; #00b1ff; #00a7ff; #009dff; #0093ff; #0089ff; #007fff; #0076ff; #006cff; #0062ff; #0058ff; #004eff; #0045ff; #003bff; #0031ff; #0027ff; #001dff; #0014ff; #000aff; #0000ff; #0500ff; #0b00ff; #1000ff; #1500ff; #1b00ff; #2000ff; #2500ff; #2b00ff; #3000ff; #3500ff; #3b00ff; #4000ff; #4500ff; #4b00ff; #5000ff; #5600ff; #5b00ff; #6000ff; #6600ff; #6b00ff; #7000ff; #7600ff; #7b00ff; #8000ff; #8600ff; #8b00ff; #8600ff; #8000ff; #7b00ff; #7600ff; #7000ff; #6b00ff; #6600ff; #6000ff; #5b00ff; #5600ff; #5000ff; #4b00ff; #4500ff; #4000ff; #3b00ff; #3500ff; #3000ff; #2b00ff; #2500ff; #2000ff; #1b00ff; #1500ff; #1000ff; #0b00ff; #0500ff; #0000ff; #000aff; #0014ff; #001dff; #0027ff; #0031ff; #003bff; #0045ff; #004eff; #0058ff; #0062ff; #006cff; #0076ff; #007fff; #0089ff; #0093ff; #009dff; #00a7ff; #00b1ff; #00baff; #00c4ff; #00ceff; #00d8ff; #00e2ff; #00ebff; #00f5ff; #00ffff; #00fff5; #00ffeb; #00ffe2; #00ffd8; #00ffce; #00ffc4; #00ffba; #00ffb1; #00ffa7; #00ff9d; #00ff93; #00ff89; #00ff80; #00ff76; #00ff6c; #00ff62; #00ff58; #00ff4e; #00ff45; #00ff3b; #00ff31; #00ff27; #00ff1d; #00ff14; #00ff0a; #00ff00; #0aff00; #14ff00; #1dff00; #27ff00; #31ff00; #3bff00; #45ff00; #4eff00; #58ff00; #62ff00; #6cff00; #76ff00; #7fff00; #89ff00; #93ff00; #9dff00; #a7ff00; #b1ff00; #baff00; #c4ff00; #ceff00; #d8ff00; #e2ff00; #ebff00; #f5ff00; #ffff00; #fffa00; #fff500; #fff000; #ffeb00; #ffe600; #ffe100; #ffdd00; #ffd800; #ffd300; #ffce00; #ffc900; #ffc400; #ffbf00; #ffba00; #ffb500; #ffb000; #ffab00; #ffa600; #ffa100; #ff9d00; #ff9800; #ff9300; #ff8e00; #ff8900; #ff8400; #ff7f00; #ff7a00; #ff7500; #ff7000; #ff6b00; #ff6700; #ff6200; #ff5d00; #ff5800; #ff5300; #ff4e00; #ff4900; #ff4400; #ff4000; #ff3b00; #ff3600; #ff3100; #ff2c00; #ff2700; #ff2200; #ff1d00; #ff1800; #ff1400; #ff0f00; #ff0a00; #ff0500;"}))', a_text);
find_replace(',fill:"#0094FF"})', ',fill:"#00FF6A"}, w("animate", {attributeName: "fill", begin: "0s", dur: "10s", repeatCount: "indefinite", values: "#ff0000; #ff0500; #ff0a00; #ff0f00; #ff1400; #ff1800; #ff1d00; #ff2200; #ff2700; #ff2c00; #ff3100; #ff3600; #ff3b00; #ff4000; #ff4400; #ff4900; #ff4e00; #ff5300; #ff5800; #ff5d00; #ff6200; #ff6700; #ff6b00; #ff7000; #ff7500; #ff7a00; #ff7f00; #ff8400; #ff8900; #ff8e00; #ff9300; #ff9800; #ff9d00; #ffa100; #ffa600; #ffab00; #ffb000; #ffb500; #ffba00; #ffbf00; #ffc400; #ffc900; #ffce00; #ffd300; #ffd800; #ffdd00; #ffe100; #ffe600; #ffeb00; #fff000; #fff500; #fffa00; #ffff00; #f5ff00; #ebff00; #e2ff00; #d8ff00; #ceff00; #c4ff00; #baff00; #b1ff00; #a7ff00; #9dff00; #93ff00; #89ff00; #7fff00; #76ff00; #6cff00; #62ff00; #58ff00; #4eff00; #45ff00; #3bff00; #31ff00; #27ff00; #1dff00; #14ff00; #0aff00; #00ff00; #00ff0a; #00ff14; #00ff1d; #00ff27; #00ff31; #00ff3b; #00ff45; #00ff4e; #00ff58; #00ff62; #00ff6c; #00ff76; #00ff80; #00ff89; #00ff93; #00ff9d; #00ffa7; #00ffb1; #00ffba; #00ffc4; #00ffce; #00ffd8; #00ffe2; #00ffeb; #00fff5; #00ffff; #00f5ff; #00ebff; #00e2ff; #00d8ff; #00ceff; #00c4ff; #00baff; #00b1ff; #00a7ff; #009dff; #0093ff; #0089ff; #007fff; #0076ff; #006cff; #0062ff; #0058ff; #004eff; #0045ff; #003bff; #0031ff; #0027ff; #001dff; #0014ff; #000aff; #0000ff; #0500ff; #0b00ff; #1000ff; #1500ff; #1b00ff; #2000ff; #2500ff; #2b00ff; #3000ff; #3500ff; #3b00ff; #4000ff; #4500ff; #4b00ff; #5000ff; #5600ff; #5b00ff; #6000ff; #6600ff; #6b00ff; #7000ff; #7600ff; #7b00ff; #8000ff; #8600ff; #8b00ff; #8600ff; #8000ff; #7b00ff; #7600ff; #7000ff; #6b00ff; #6600ff; #6000ff; #5b00ff; #5600ff; #5000ff; #4b00ff; #4500ff; #4000ff; #3b00ff; #3500ff; #3000ff; #2b00ff; #2500ff; #2000ff; #1b00ff; #1500ff; #1000ff; #0b00ff; #0500ff; #0000ff; #000aff; #0014ff; #001dff; #0027ff; #0031ff; #003bff; #0045ff; #004eff; #0058ff; #0062ff; #006cff; #0076ff; #007fff; #0089ff; #0093ff; #009dff; #00a7ff; #00b1ff; #00baff; #00c4ff; #00ceff; #00d8ff; #00e2ff; #00ebff; #00f5ff; #00ffff; #00fff5; #00ffeb; #00ffe2; #00ffd8; #00ffce; #00ffc4; #00ffba; #00ffb1; #00ffa7; #00ff9d; #00ff93; #00ff89; #00ff80; #00ff76; #00ff6c; #00ff62; #00ff58; #00ff4e; #00ff45; #00ff3b; #00ff31; #00ff27; #00ff1d; #00ff14; #00ff0a; #00ff00; #0aff00; #14ff00; #1dff00; #27ff00; #31ff00; #3bff00; #45ff00; #4eff00; #58ff00; #62ff00; #6cff00; #76ff00; #7fff00; #89ff00; #93ff00; #9dff00; #a7ff00; #b1ff00; #baff00; #c4ff00; #ceff00; #d8ff00; #e2ff00; #ebff00; #f5ff00; #ffff00; #fffa00; #fff500; #fff000; #ffeb00; #ffe600; #ffe100; #ffdd00; #ffd800; #ffd300; #ffce00; #ffc900; #ffc400; #ffbf00; #ffba00; #ffb500; #ffb000; #ffab00; #ffa600; #ffa100; #ff9d00; #ff9800; #ff9300; #ff8e00; #ff8900; #ff8400; #ff7f00; #ff7a00; #ff7500; #ff7000; #ff6b00; #ff6700; #ff6200; #ff5d00; #ff5800; #ff5300; #ff4e00; #ff4900; #ff4400; #ff4000; #ff3b00; #ff3600; #ff3100; #ff2c00; #ff2700; #ff2200; #ff1d00; #ff1800; #ff1400; #ff0f00; #ff0a00; #ff0500;"}))', a_text);
find_replace(',stroke:"#085AF6"})', ',stroke:"#00FF6A"}, w("animate", {attributeName: "stroke", begin: "0s", dur: "10s", repeatCount: "indefinite", values: "#ff0000; #ff0500; #ff0a00; #ff0f00; #ff1400; #ff1800; #ff1d00; #ff2200; #ff2700; #ff2c00; #ff3100; #ff3600; #ff3b00; #ff4000; #ff4400; #ff4900; #ff4e00; #ff5300; #ff5800; #ff5d00; #ff6200; #ff6700; #ff6b00; #ff7000; #ff7500; #ff7a00; #ff7f00; #ff8400; #ff8900; #ff8e00; #ff9300; #ff9800; #ff9d00; #ffa100; #ffa600; #ffab00; #ffb000; #ffb500; #ffba00; #ffbf00; #ffc400; #ffc900; #ffce00; #ffd300; #ffd800; #ffdd00; #ffe100; #ffe600; #ffeb00; #fff000; #fff500; #fffa00; #ffff00; #f5ff00; #ebff00; #e2ff00; #d8ff00; #ceff00; #c4ff00; #baff00; #b1ff00; #a7ff00; #9dff00; #93ff00; #89ff00; #7fff00; #76ff00; #6cff00; #62ff00; #58ff00; #4eff00; #45ff00; #3bff00; #31ff00; #27ff00; #1dff00; #14ff00; #0aff00; #00ff00; #00ff0a; #00ff14; #00ff1d; #00ff27; #00ff31; #00ff3b; #00ff45; #00ff4e; #00ff58; #00ff62; #00ff6c; #00ff76; #00ff80; #00ff89; #00ff93; #00ff9d; #00ffa7; #00ffb1; #00ffba; #00ffc4; #00ffce; #00ffd8; #00ffe2; #00ffeb; #00fff5; #00ffff; #00f5ff; #00ebff; #00e2ff; #00d8ff; #00ceff; #00c4ff; #00baff; #00b1ff; #00a7ff; #009dff; #0093ff; #0089ff; #007fff; #0076ff; #006cff; #0062ff; #0058ff; #004eff; #0045ff; #003bff; #0031ff; #0027ff; #001dff; #0014ff; #000aff; #0000ff; #0500ff; #0b00ff; #1000ff; #1500ff; #1b00ff; #2000ff; #2500ff; #2b00ff; #3000ff; #3500ff; #3b00ff; #4000ff; #4500ff; #4b00ff; #5000ff; #5600ff; #5b00ff; #6000ff; #6600ff; #6b00ff; #7000ff; #7600ff; #7b00ff; #8000ff; #8600ff; #8b00ff; #8600ff; #8000ff; #7b00ff; #7600ff; #7000ff; #6b00ff; #6600ff; #6000ff; #5b00ff; #5600ff; #5000ff; #4b00ff; #4500ff; #4000ff; #3b00ff; #3500ff; #3000ff; #2b00ff; #2500ff; #2000ff; #1b00ff; #1500ff; #1000ff; #0b00ff; #0500ff; #0000ff; #000aff; #0014ff; #001dff; #0027ff; #0031ff; #003bff; #0045ff; #004eff; #0058ff; #0062ff; #006cff; #0076ff; #007fff; #0089ff; #0093ff; #009dff; #00a7ff; #00b1ff; #00baff; #00c4ff; #00ceff; #00d8ff; #00e2ff; #00ebff; #00f5ff; #00ffff; #00fff5; #00ffeb; #00ffe2; #00ffd8; #00ffce; #00ffc4; #00ffba; #00ffb1; #00ffa7; #00ff9d; #00ff93; #00ff89; #00ff80; #00ff76; #00ff6c; #00ff62; #00ff58; #00ff4e; #00ff45; #00ff3b; #00ff31; #00ff27; #00ff1d; #00ff14; #00ff0a; #00ff00; #0aff00; #14ff00; #1dff00; #27ff00; #31ff00; #3bff00; #45ff00; #4eff00; #58ff00; #62ff00; #6cff00; #76ff00; #7fff00; #89ff00; #93ff00; #9dff00; #a7ff00; #b1ff00; #baff00; #c4ff00; #ceff00; #d8ff00; #e2ff00; #ebff00; #f5ff00; #ffff00; #fffa00; #fff500; #fff000; #ffeb00; #ffe600; #ffe100; #ffdd00; #ffd800; #ffd300; #ffce00; #ffc900; #ffc400; #ffbf00; #ffba00; #ffb500; #ffb000; #ffab00; #ffa600; #ffa100; #ff9d00; #ff9800; #ff9300; #ff8e00; #ff8900; #ff8400; #ff7f00; #ff7a00; #ff7500; #ff7000; #ff6b00; #ff6700; #ff6200; #ff5d00; #ff5800; #ff5300; #ff4e00; #ff4900; #ff4400; #ff4000; #ff3b00; #ff3600; #ff3100; #ff2c00; #ff2700; #ff2200; #ff1d00; #ff1800; #ff1400; #ff0f00; #ff0a00; #ff0500;"}))', a_text);
find_replace(',stroke:"#085AF6",color:"transparent"})', ',stroke:"#00FF6A",color: "transparent"}, w("animate", {attributeName: "stroke", begin: "0s", dur: "10s", repeatCount: "indefinite", values: "#ff0000; #ff0500; #ff0a00; #ff0f00; #ff1400; #ff1800; #ff1d00; #ff2200; #ff2700; #ff2c00; #ff3100; #ff3600; #ff3b00; #ff4000; #ff4400; #ff4900; #ff4e00; #ff5300; #ff5800; #ff5d00; #ff6200; #ff6700; #ff6b00; #ff7000; #ff7500; #ff7a00; #ff7f00; #ff8400; #ff8900; #ff8e00; #ff9300; #ff9800; #ff9d00; #ffa100; #ffa600; #ffab00; #ffb000; #ffb500; #ffba00; #ffbf00; #ffc400; #ffc900; #ffce00; #ffd300; #ffd800; #ffdd00; #ffe100; #ffe600; #ffeb00; #fff000; #fff500; #fffa00; #ffff00; #f5ff00; #ebff00; #e2ff00; #d8ff00; #ceff00; #c4ff00; #baff00; #b1ff00; #a7ff00; #9dff00; #93ff00; #89ff00; #7fff00; #76ff00; #6cff00; #62ff00; #58ff00; #4eff00; #45ff00; #3bff00; #31ff00; #27ff00; #1dff00; #14ff00; #0aff00; #00ff00; #00ff0a; #00ff14; #00ff1d; #00ff27; #00ff31; #00ff3b; #00ff45; #00ff4e; #00ff58; #00ff62; #00ff6c; #00ff76; #00ff80; #00ff89; #00ff93; #00ff9d; #00ffa7; #00ffb1; #00ffba; #00ffc4; #00ffce; #00ffd8; #00ffe2; #00ffeb; #00fff5; #00ffff; #00f5ff; #00ebff; #00e2ff; #00d8ff; #00ceff; #00c4ff; #00baff; #00b1ff; #00a7ff; #009dff; #0093ff; #0089ff; #007fff; #0076ff; #006cff; #0062ff; #0058ff; #004eff; #0045ff; #003bff; #0031ff; #0027ff; #001dff; #0014ff; #000aff; #0000ff; #0500ff; #0b00ff; #1000ff; #1500ff; #1b00ff; #2000ff; #2500ff; #2b00ff; #3000ff; #3500ff; #3b00ff; #4000ff; #4500ff; #4b00ff; #5000ff; #5600ff; #5b00ff; #6000ff; #6600ff; #6b00ff; #7000ff; #7600ff; #7b00ff; #8000ff; #8600ff; #8b00ff; #8600ff; #8000ff; #7b00ff; #7600ff; #7000ff; #6b00ff; #6600ff; #6000ff; #5b00ff; #5600ff; #5000ff; #4b00ff; #4500ff; #4000ff; #3b00ff; #3500ff; #3000ff; #2b00ff; #2500ff; #2000ff; #1b00ff; #1500ff; #1000ff; #0b00ff; #0500ff; #0000ff; #000aff; #0014ff; #001dff; #0027ff; #0031ff; #003bff; #0045ff; #004eff; #0058ff; #0062ff; #006cff; #0076ff; #007fff; #0089ff; #0093ff; #009dff; #00a7ff; #00b1ff; #00baff; #00c4ff; #00ceff; #00d8ff; #00e2ff; #00ebff; #00f5ff; #00ffff; #00fff5; #00ffeb; #00ffe2; #00ffd8; #00ffce; #00ffc4; #00ffba; #00ffb1; #00ffa7; #00ff9d; #00ff93; #00ff89; #00ff80; #00ff76; #00ff6c; #00ff62; #00ff58; #00ff4e; #00ff45; #00ff3b; #00ff31; #00ff27; #00ff1d; #00ff14; #00ff0a; #00ff00; #0aff00; #14ff00; #1dff00; #27ff00; #31ff00; #3bff00; #45ff00; #4eff00; #58ff00; #62ff00; #6cff00; #76ff00; #7fff00; #89ff00; #93ff00; #9dff00; #a7ff00; #b1ff00; #baff00; #c4ff00; #ceff00; #d8ff00; #e2ff00; #ebff00; #f5ff00; #ffff00; #fffa00; #fff500; #fff000; #ffeb00; #ffe600; #ffe100; #ffdd00; #ffd800; #ffd300; #ffce00; #ffc900; #ffc400; #ffbf00; #ffba00; #ffb500; #ffb000; #ffab00; #ffa600; #ffa100; #ff9d00; #ff9800; #ff9300; #ff8e00; #ff8900; #ff8400; #ff7f00; #ff7a00; #ff7500; #ff7000; #ff6b00; #ff6700; #ff6200; #ff5d00; #ff5800; #ff5300; #ff4e00; #ff4900; #ff4400; #ff4000; #ff3b00; #ff3600; #ff3100; #ff2c00; #ff2700; #ff2200; #ff1d00; #ff1800; #ff1400; #ff0f00; #ff0a00; #ff0500;"}))', a_text);
find_replace(',fill:"#085AF6"})', ',fill:"#00FF6A"}, w("animate", {attributeName: "fill", begin: "0s", dur: "10s", repeatCount: "indefinite", values: "#ff0000; #ff0500; #ff0a00; #ff0f00; #ff1400; #ff1800; #ff1d00; #ff2200; #ff2700; #ff2c00; #ff3100; #ff3600; #ff3b00; #ff4000; #ff4400; #ff4900; #ff4e00; #ff5300; #ff5800; #ff5d00; #ff6200; #ff6700; #ff6b00; #ff7000; #ff7500; #ff7a00; #ff7f00; #ff8400; #ff8900; #ff8e00; #ff9300; #ff9800; #ff9d00; #ffa100; #ffa600; #ffab00; #ffb000; #ffb500; #ffba00; #ffbf00; #ffc400; #ffc900; #ffce00; #ffd300; #ffd800; #ffdd00; #ffe100; #ffe600; #ffeb00; #fff000; #fff500; #fffa00; #ffff00; #f5ff00; #ebff00; #e2ff00; #d8ff00; #ceff00; #c4ff00; #baff00; #b1ff00; #a7ff00; #9dff00; #93ff00; #89ff00; #7fff00; #76ff00; #6cff00; #62ff00; #58ff00; #4eff00; #45ff00; #3bff00; #31ff00; #27ff00; #1dff00; #14ff00; #0aff00; #00ff00; #00ff0a; #00ff14; #00ff1d; #00ff27; #00ff31; #00ff3b; #00ff45; #00ff4e; #00ff58; #00ff62; #00ff6c; #00ff76; #00ff80; #00ff89; #00ff93; #00ff9d; #00ffa7; #00ffb1; #00ffba; #00ffc4; #00ffce; #00ffd8; #00ffe2; #00ffeb; #00fff5; #00ffff; #00f5ff; #00ebff; #00e2ff; #00d8ff; #00ceff; #00c4ff; #00baff; #00b1ff; #00a7ff; #009dff; #0093ff; #0089ff; #007fff; #0076ff; #006cff; #0062ff; #0058ff; #004eff; #0045ff; #003bff; #0031ff; #0027ff; #001dff; #0014ff; #000aff; #0000ff; #0500ff; #0b00ff; #1000ff; #1500ff; #1b00ff; #2000ff; #2500ff; #2b00ff; #3000ff; #3500ff; #3b00ff; #4000ff; #4500ff; #4b00ff; #5000ff; #5600ff; #5b00ff; #6000ff; #6600ff; #6b00ff; #7000ff; #7600ff; #7b00ff; #8000ff; #8600ff; #8b00ff; #8600ff; #8000ff; #7b00ff; #7600ff; #7000ff; #6b00ff; #6600ff; #6000ff; #5b00ff; #5600ff; #5000ff; #4b00ff; #4500ff; #4000ff; #3b00ff; #3500ff; #3000ff; #2b00ff; #2500ff; #2000ff; #1b00ff; #1500ff; #1000ff; #0b00ff; #0500ff; #0000ff; #000aff; #0014ff; #001dff; #0027ff; #0031ff; #003bff; #0045ff; #004eff; #0058ff; #0062ff; #006cff; #0076ff; #007fff; #0089ff; #0093ff; #009dff; #00a7ff; #00b1ff; #00baff; #00c4ff; #00ceff; #00d8ff; #00e2ff; #00ebff; #00f5ff; #00ffff; #00fff5; #00ffeb; #00ffe2; #00ffd8; #00ffce; #00ffc4; #00ffba; #00ffb1; #00ffa7; #00ff9d; #00ff93; #00ff89; #00ff80; #00ff76; #00ff6c; #00ff62; #00ff58; #00ff4e; #00ff45; #00ff3b; #00ff31; #00ff27; #00ff1d; #00ff14; #00ff0a; #00ff00; #0aff00; #14ff00; #1dff00; #27ff00; #31ff00; #3bff00; #45ff00; #4eff00; #58ff00; #62ff00; #6cff00; #76ff00; #7fff00; #89ff00; #93ff00; #9dff00; #a7ff00; #b1ff00; #baff00; #c4ff00; #ceff00; #d8ff00; #e2ff00; #ebff00; #f5ff00; #ffff00; #fffa00; #fff500; #fff000; #ffeb00; #ffe600; #ffe100; #ffdd00; #ffd800; #ffd300; #ffce00; #ffc900; #ffc400; #ffbf00; #ffba00; #ffb500; #ffb000; #ffab00; #ffa600; #ffa100; #ff9d00; #ff9800; #ff9300; #ff8e00; #ff8900; #ff8400; #ff7f00; #ff7a00; #ff7500; #ff7000; #ff6b00; #ff6700; #ff6200; #ff5d00; #ff5800; #ff5300; #ff4e00; #ff4900; #ff4400; #ff4000; #ff3b00; #ff3600; #ff3100; #ff2c00; #ff2700; #ff2200; #ff1d00; #ff1800; #ff1400; #ff0f00; #ff0a00; #ff0500;"}))', a_text);
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'image_hacks_updateCompose';
if (image_hacks){
// IMAGE HACKS
reset_a_text(a_text, text, cur_tag);
// find_replace("u.resize(500,g.a.AUTO).quality(o)", "u.resize(508,g.a.AUTO).quality(o)", a_text); // Fix size inconsistency with Twetch display size // Twetch has implemented the fix.
// find_replace("a=90001", "a=(n.length-22)*3/4", a_text); // Fetch real image size // Twetch has implemented the fix.
// find_replace("a=s.toString().length", "a=(s.toString().length-22)*3/4", a_text); // Fix image size bug // Twetch has implemented the fix.
// find_replace("if(!(a>=9e4)){", "if(!(a>='+image_conversion_threshold+')){if(o==100){return o -= 1, s = n.replace(/^data\:image\\/.*\;/g,'data:image/jpeg;'), t.next=17, g.a.read(n);}", a_text); // Fix image size bug and don't resize images that can fit a B:// transaction. Also fix B:// max size // Twetch has implemented the fix.
// find_replace('i=this.getContentType(e),["image/png","image/jpeg"].includes(i)', '((o=3*(e.toString().length-22)/4)>r)&&(i=this.getContentType(e),["image/png","image/jpeg"].includes(i))', a_text); // Fix APNG // Obsolete
find_replace('result,95e3)', 'result,'+image_conversion_threshold+')', a_text); // Bump Twetch max image size limit to 98.8kB
// PNG conversion is limited to 588px dimensions! We should definitely convert big PNGs to JPEG by default! HARRY PLEASE: WE NEED TO CONVERT PNGs TO JPEG!!!!
//find_replace('getBase64Async(s.AUTO)', 'getBase64Async("image/jpeg")', a_text); // Doesn't work
//find_replace('getBase64Async(s.AUTO)', 'getBase64Async("image/jpeg")', a_text); // Doesn't work
// Don't force JPEG conversion on everything
find_replace('getBase64Async("image/jpeg")', 'getBase64Async(i)', a_text); // Need to investigate if this is still relevant
// Force JPEG conversion from PNG if size of PNG is above the OP_RETURN limit + get mimeType
find_replace('return e.props.onCompressing(!0)', 'window.Klimenos_image_original_mimeType = r.result.match(/^data:.*\;/g)[0].replace(/^data:/g, "").replace(/\;$/g, ""); if ((r.result.length-22)*3/4 > '+image_conversion_threshold+') { Jimp.read(r.result).then(img => {img.getBase64("image/jpeg", (err, res) => {window.Klimenos_img_e_jpeg_from_png_hack = res;})}); } else { window.Klimenos_img_e_jpeg_from_png_hack = null}; return e.props.onCompressing(!0)', a_text);
// Get file extension if it exists
find_replace('t.target.files[0];', 'function(){var n = t.target.files[0].name; window.Klimenos_image_original_extension = n.substring(n.lastIndexOf(".") + 1); return t.target.files[0];}();', a_text);
// Force JPEG conversion from PNG if window.Klimenos_img_e_jpeg_from_png_hack isn't null
find_replace('return a=t.sent', 'if ( window.Klimenos_img_e_jpeg_from_png_hack != null ){ i = "image/jpeg"; }; return a=t.sent', a_text);
find_replace('a.getBase64Async(i)', 'function(){if (window.Klimenos_img_e_jpeg_from_png_hack != null) {return window.Klimenos_img_e_jpeg_from_png_hack;} else {return a.getBase64Async(i);};}()', a_text);
// Code to handle other types of format
//find_replace('image/jpeg, image/png, image/gif', 'image/\*, image/webp, video/mp4', a_text); // WebP mimeType not recognised by Firefox... so it just breaks the accept... Firefox devs...
find_replace(/\"file\",accept:\"((?!\").)*\"/g, '"file"', a_text); // Accept any kind of file
find_replace('"image/png","image/gif"', '"image/png","image/gif","image/tiff","image/svg+xml","image/bmp","image/webp","video/mp4"', a_text); //
find_replace('"image/png":"png","image/gif":"gif"', '"image/png":"png","image/gif":"gif","image/tiff":"tiff","image/svg+xml":"svg","image/bmp":"bmp","image/webp":"webp","video/mp4":"mp4"', a_text); //
// Higher resolution upload
// DEBUG
find_replace('.resize(508,s.AUTO)', '.resize((function(){if (window.Klimenos_img_width_hack == null || window.Klimenos_img_e_hack != e) { if ( window.Klimenos_img_e_jpeg_from_png_hack != null ){ e = window.Klimenos_img_e_jpeg_from_png_hack; console.log("GO!"); }; window.Klimenos_o_count = 0; if (window.Klimenos_image_original_mimeType == "image/jpeg"){ window.Klimenos_o_count_threshold = 100-'+image_quality_redim_jpeg+'; } else if (window.Klimenos_image_original_mimeType == "image/png"){ window.Klimenos_o_count_threshold = 100-'+image_quality_redim_png+'; } else { window.Klimenos_o_count_threshold = 100-'+image_quality_redim_other+'; }; window.Klimenos_img_width_hack = 0; window.Klimenos_img_e_hack = e; var i = new Image(); i.src = e; i.onload = function() {}; var r = new XMLHttpRequest(); r.open("GET", e, false); r.send(null); if (r.status === 200) { var i_ = document.createElement("img"); i_.src = e; }; console.log(i_.complete); console.log(i_.naturalWidth); window.Klimenos_img_width_hack = i_.naturalWidth; window.Klimenos_img_height_hack = i_.naturalHeight; } console.log("final ret:" + window.Klimenos_img_width_hack); var m; console.log("echo: " + e.match(/^data:image\\/png\;/g)); console.log("o: "+window.Klimenos_o_count); var n; if (""+e.match(/^data:image\\/png\;/g) == "data:image/png;"){ m = '+max_image_width_and_height_png+'; if (window.Klimenos_img_width_hack > window.Klimenos_img_height_hack) { console.log("PNG width longer: " + window.Klimenos_img_width_hack); if (window.Klimenos_img_width_hack > m) { n = m; if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; console.log("resized width: " + n); return n; } } else { console.log("PNG width smaller: " + window.Klimenos_img_width_hack); if (window.Klimenos_img_width_hack > m) { n = Math.floor(window.Klimenos_img_width_hack * m / window.Klimenos_img_height_hack); if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; console.log("resized width: " + n); return n; } } } else { m = '+max_image_width_and_height_jpeg+'; if (window.Klimenos_img_width_hack > window.Klimenos_img_height_hack) { console.log("JPEG width longer: " + window.Klimenos_img_width_hack); if (window.Klimenos_img_width_hack > m) { n = m; if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; console.log("resized width: " + n); return n; } } else { console.log("JPEG width smaller: " + window.Klimenos_img_width_hack); if (window.Klimenos_img_width_hack > m) { n = Math.floor(window.Klimenos_img_width_hack * m / window.Klimenos_img_height_hack); if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; console.log("resized width: " + n); return n; } } } n = window.Klimenos_img_width_hack; if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; console.log("fine width: " + n); return n;})(),s.AUTO)', a_text); // Decrease the width to 700px, only if the image width is >700px.
// WITHOUT DEBUG
//find_replace('.resize(508,s.AUTO)', '.resize((function(){if (window.Klimenos_img_width_hack == null || window.Klimenos_img_e_hack != e) { if ( window.Klimenos_img_e_jpeg_from_png_hack != null ){ e = window.Klimenos_img_e_jpeg_from_png_hack; console.log("GO!"); }; window.Klimenos_o_count = 0; if (window.Klimenos_image_original_mimeType == "image/jpeg"){ window.Klimenos_o_count_threshold = 100-'+image_quality_redim_jpeg+'; } else if (window.Klimenos_image_original_mimeType == "image/png"){ window.Klimenos_o_count_threshold = 100-'+image_quality_redim_png+'; } else { window.Klimenos_o_count_threshold = 100-'+image_quality_redim_other+'; }; window.Klimenos_img_width_hack = 0; window.Klimenos_img_e_hack = e; var i = new Image(); i.src = e; i.onload = function() {}; var r = new XMLHttpRequest(); r.open("GET", e, false); r.send(null); if (r.status === 200) { var i_ = document.createElement("img"); i_.src = e; }; window.Klimenos_img_width_hack = i_.naturalWidth; window.Klimenos_img_height_hack = i_.naturalHeight; } var m; var n; if (""+e.match(/^data:image\\/png\;/g) == "data:image/png;"){ m = '+max_image_width_and_height_png+'; if (window.Klimenos_img_width_hack > window.Klimenos_img_height_hack) { if (window.Klimenos_img_width_hack > m) { n = m; if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; return n; } } else { if (window.Klimenos_img_width_hack > m) { n = Math.floor(window.Klimenos_img_width_hack * m / window.Klimenos_img_height_hack); if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; return n; } } } else { m = '+max_image_width_and_height_jpeg+'; if (window.Klimenos_img_width_hack > window.Klimenos_img_height_hack) { if (window.Klimenos_img_width_hack > m) { n = m; if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; return n; } } else { if (window.Klimenos_img_width_hack > m) { n = Math.floor(window.Klimenos_img_width_hack * m / window.Klimenos_img_height_hack); if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; return n; } } } n = window.Klimenos_img_width_hack; if (window.Klimenos_o_count > window.Klimenos_o_count_threshold){ n = Math.ceil(n-n*(window.Klimenos_o_count-window.Klimenos_o_count_threshold)/(100-window.Klimenos_o_count_threshold)); } window.Klimenos_o_count++; return n;})(),"image/jpeg")', a_text); // Decrease the width to 700px, only if the image width is >700px.
// Fetch original mimeType and extension and store them
// DEBUG
//find_replace('return n.wrap(function(t){', 'return n.wrap(function(t){window.Klimenos_image_original_mimeType=this.getContentType(e);window.Klimenos_image_original_extension=this.getFileExtension(e);console.log("mimeType:"+window.Klimenos_image_original_mimeType);console.log("extension:"+window.Klimenos_image_original_extension);', a_text); // Fetch the original mimeType and store it in Klimenos_image_original_mimeType
// WITHOUT DEBUG
find_replace('return n.wrap(function(t){', 'return n.wrap(function(t){window.Klimenos_image_original_mimeType=this.getContentType(e);window.Klimenos_image_original_extension=this.getFileExtension(e);', a_text); // Fetch the original mimeType and store it in Klimenos_image_original_mimeType
//find_replace("s.read(e)", "s.read(e.replace(/^data\:image\\/.*\;/g,'data:image/jpeg;'))", a_text); // Not used
//find_replace('t.abrupt("return", e)', 't.abrupt("return", e.replace(/^data\:image\\/.*\;/g,"data:image/jpeg;")', a_text); // Not used
// FIXING BUGS AGAIN... OMG HARRY, WHAT ARE YOU DOING?!
// Fix decodeArrayBuffer bug - m[1] has ending zeros (seen for SVG)... because decodeArrayBuffer size is wrong! You allocate a buffer that is too long... because you ignore the "=" of base64!
// Same issue for max file size... but I'm lazy to implement the fix.
find_replace('t.length/4*3,', '(function(){var i = 0; var l = t.length; if(""+t[l-1] == "=")i++; if(""+t[l-2] == "=")i++; return t.length/4*3-i})(),', a_text); // Come on Harry, this is not how you calculate the size of a file!
// HANDLING SIGNING
//find_replace('"state.imageData","").split("data:".concat(o.mimeType,";base64,")).join(""),o.mimeType', '"state.imageData","").split("data:".concat("image/jpeg",";base64,")).join(""),"image/jpeg"', a_text); // Bypass signing mimeType
//find_replace("n.signPost(u);", 'n.signPost((function(){u[2]="image/jpeg"; u[1]=u[1].replace(/^data\:image\\/.*\;/g,"data:image/jpeg;"); u[4]=u[4].replace(/\\..*$/g,".jpg"); return u;})());', a_text); // Better signing bypass
// DEBUG n
//find_replace("n.signPost(u);", '(function(){var ret = n.signPost((function(){u[2]="image/jpeg"; u[4]=u[4].replace(/\\..*$/g,"."+window.Klimenos_image_original_extension); return u;})()); console.log(n); return ret;})();', a_text); // Better signing bypass and extension rewriting (optional extension rewriting)
// WITHOUT DEBUG
find_replace("n.signPost(l);", 'n.signPost((function(){l[1]=l[1].replace(/^data\:((?!\\/).)*\\/.*\;base64,/g,""); l[2]="image/jpeg"; l[4]=l[4].replace(/\\..*$/g,"."+window.Klimenos_image_original_extension); return l;})());', a_text); // Better signing bypass and extension rewriting (optional extension rewriting) + Dirty patch for u[1], because also modified at this stage by GraphQL handle post-signing
// HANDLING PAYMENT
find_replace('x.a.Buffer.from(G.a.decodeArrayBuffer(b[1]))', '(function(){var ret = x.a.Buffer.from(G.a.decodeArrayBuffer(b[1])); b[2]=""+window.Klimenos_image_original_mimeType; return ret;})()', a_text); // We patch m[2] here because... why not, we can! xD
// HANDLING GRAPHQL
find_replace(/.\..\.getContentType\(this\.state\.imageData\)/g, '"image/jpeg"', a_text); // Fake JPEG mimeType for graphQL (unfortunately also applies to pre-sining... need to find a better patch)
// UNUSED FOR SURE
//find_replace('v.a.get(this,"state.imageData","").split("data:".concat(o.mimeType,";base64,")).join(""),o.mimeType,', 'v.a.get(this,"state.imageData","").split("data:".concat(o.mimeType,";base64,")).join(""),""+window.Klimenos_image_original_mimeType,', a_text); // Restore original mimeType for Money Button
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'activate_svg_updateCompose';
if (activate_svg){
// ACTIVATE SVG EDITOR
reset_a_text(a_text, text, cur_tag);
//find_replace("key:\"character-counter\",count:e,", "key:\"character-counter\",count:'\u221E',", a_text); // Unlimited characters icon
find_replace('className:t.characterCounter', 'className: t.characterCounter, onChange: function(){'+Klimenos_activate_svg_function+'}()', a_text); // Unlimited characters clickable
//find_replace('characterCounter:{', 'characterCounter:{cursor: "pointer",', a_text); // Make characterCounter clickable
//find_replace("disabled:o,onClick:this.handleClickPreview.bind(this)", "disabled:false,onClick:this.handleClickPreview.bind(this)", a_text); // Unlimited characters
find_replace('readAsDataURL(n)', 'readAsDataURL(function(){if (window.KlimenosSVGActivator == true && window.Klimenos_activate_svg_hack_image != null) { return new File([""], "") } else { return n; }; }())', a_text); // Trick with an empty object file
//find_replace('{key:"renderUploadButton"', '{key: "renderUploadButton", value: function() { return O("input", { id: "klimenos-input", style: { display: "none" }, onClick: this.handleChangeFileInput.bind(this) });}},{key:"renderUploadButton"', a_text);
// OLD HACKS
//find_replace("this.renderSignError(),", "", a_text); // Remove signing error
//find_replace("n.signPost(u);", "true;n.signPost(u);", a_text); // Bypass signing response
//find_replace(/\[\"19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut\",r,/g, '["19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut",null,', a_text); // Bypass signing
// NEW HACK WITH SVG
// WITH DEBUG
//find_replace('.a.compress(r.result', '.a.compress(function(){console.log("window.Klimenos_activate_svg_hack_image: "+window.Klimenos_activate_svg_hack_image); if (window.KlimenosSVGActivator == true && window.Klimenos_activate_svg_hack_image != null) { return window.Klimenos_activate_svg_hack_image; } else { return r.result; };}()', a_text); // Hook function that compresses images
// WITHOUT DEBUG
find_replace('.a.compress(r.result', '.a.compress(function(){if (window.KlimenosSVGActivator == true && window.Klimenos_activate_svg_hack_image != null) { return window.Klimenos_activate_svg_hack_image; } else { return r.result; };}()', a_text); // Hook function that compresses images
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'adjust_costs_updateCompose';
if (adjust_costs){
// ADJUST TWETCH PRICES
reset_a_text(a_text, text, cur_tag);
if (twetch_fee_cost != null){
find_replace(/\"1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf\",currency\:\"USD\",amount\:((?!\}).)*\}/g, '"1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf",currency:"USD",amount:"'+twetch_fee_cost+'"}', a_text);
}
if (reply_cost != null){
//find_replace('amount:d?"0.01":"0.02"', 'amount:d?"'+reply_cost+'":"'+reply_cost*2+'"', a_text); // No longer found, was replaced by w
//find_replace('"1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf",currency:"USD",amount:w', '"1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf",currency:"USD",amount:d?"'+reply_cost+'":"'+reply_cost*2+'"', a_text); // Incorrect
//find_replace('amount:"0.01"', 'amount:"'+reply_cost+'"', a_text); // No longer found, was replaced by q.a.replyPrice
find_replace(/.\..\.replyPrice/g, ''+reply_cost, a_text);
}
if (reply_branch_cost != null){
find_replace(/.\..\.branchPrice/g, ''+reply_branch_cost, a_text);
}
if (mention_cost != null){
//find_replace('amount:"0.001"', 'amount:"'+mention_cost+'"', a_text); // No longer found, was replaced by q.a.mentionPrice
find_replace(/.\..\.mentionPrice/g, ''+mention_cost, a_text);
}
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'disable_twetch_fees_updateCompose';
if (disable_twetch_fees){
// DISABLE TWETCH FEES
reset_a_text(a_text, text, cur_tag);
//find_replace('{to:"".concat(t&&t.env&&t.env.FEE_MONEY_BUTTON_ID||"6757","@moneybutton.com"),currency:"USD",amount:d?"0.01":"0.02"}', '', a_text); // old method
find_replace(/\{to:((?!\|).)*\|\|"((?!\").)*\",currency:\"USD\",amount:((?!\}).)*\}/g, '', a_text);
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'activate_darkMode_updateCompose';
if (activate_darkMode){
// FORCE ACTIVATION OF DARK MODE
reset_a_text(a_text, text, cur_tag);
find_replace('isDarkMode",!1)', 'isDarkMode",!1)||true', a_text, force_ok); // Enable darkMode
find_replace('this.props.auth.me.isDarkMode?', 'true?', a_text, force_ok); // Enable darkMode
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.textContent = text;
var head = document.getElementsByTagName('head')[0];
head.appendChild(newScript);
}
function updateCommon(text) {
//console.log('replacing whatever in compose');
cur_tag = 'adjust_costs_updateCommon';
if (adjust_costs){
reset_a_text(a_text, text, cur_tag);
if (twetch_fee_cost != null){
find_replace(/\"1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf\",currency\:\"USD\",amount\:((?!\}).)*\}/g, '"1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf",currency:"USD",amount:"'+twetch_fee_cost+'"}', a_text);
}
if (like_cost != null){
find_replace('.LIKE_PRICE||"0.05")', '.LIKE_PRICE||"'+like_cost+'")', a_text);
}
if (follow_cost != null){
find_replace('amount:"0.08"', 'amount:"'+follow_cost+'"', a_text);
}
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'disable_twetch_fees_updateCommon';
if (disable_twetch_fees){
reset_a_text(a_text, text, cur_tag);
//find_replace(/push\(\{to:\"\"\.concat\(((?!\)).)*\.FEE_MONEY_BUTTON_ID\|\|\"6757\",\"@moneybutton\.com\"\),currency:\"USD\",amount:((?!\}).)*\}\),.\./g, '', a_text); // Old patch for follow
//find_replace(/\{to:\"\"\.concat\(((?!\)).)*\.FEE_MONEY_BUTTON_ID\|\|\"6757\",\"@moneybutton\.com\"\),currency:\"USD\",amount:((?!\}).)*\}/g, '', a_text); // Old patch for likes
find_replace(/.\.push\(\{to:((?!\|).)*\|\|"((?!\").)*\",currency:\"USD\",amount:((?!\}).)*\}\),/g, '', a_text);
find_replace(/\{to:((?!\|).)*\|\|"((?!\").)*\",currency:\"USD\",amount:((?!\}).)*\}/g, '', a_text);
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'activate_darkMode_updateCommon';
if (activate_darkMode){
reset_a_text(a_text, text, cur_tag);
find_replace('isDarkMode",!1)', 'isDarkMode",!1)||true', a_text, force_ok); // Enable darkMode
find_replace('this.props.auth.me.isDarkMode?', 'true?', a_text, force_ok); // Enable darkMode
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.textContent = text;
var head = document.getElementsByTagName('head')[0];
head.appendChild(newScript);
}
function updateApp(text) {
//console.log('replacing whatever in app');
cur_tag = 'activate_darkMode_updateApp';
if (activate_darkMode){
reset_a_text(a_text, text, cur_tag);
find_replace('isDarkMode",!1)', 'isDarkMode",!1)||true', a_text, force_ok); // Enable darkMode
find_replace('this.props.auth.me.isDarkMode?', 'true?', a_text, force_ok); // Enable darkMode
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.textContent = text;
var head = document.getElementsByTagName('head')[0];
head.appendChild(newScript);
}
function updateSettings(text) {
//console.log('replacing whatever in app');
cur_tag = 'activate_darkMode_updateSettings';
if (activate_darkMode){
reset_a_text(a_text, text, cur_tag);
find_replace('isDarkMode",!1)', 'isDarkMode",!1)||true', a_text, force_ok); // Enable darkMode
find_replace('this.props.auth.me.isDarkMode?', 'true?', a_text, force_ok); // Enable darkMode
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
cur_tag = 'adjust_costs_updateSettings';
if (adjust_costs){
reset_a_text(a_text, text, cur_tag);
if (feature_cost != null){
find_replace('amount:"1.00"', 'amount:"'+feature_cost+'"', a_text);
}
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.textContent = text;
var head = document.getElementsByTagName('head')[0];
head.appendChild(newScript);
}
function updateIndex(text) {
//console.log('replacing whatever in app');
cur_tag = 'non_dynamic_pagenav_updateIndex';
if (non_dynamic_pagenav){
reset_a_text(a_text, text, cur_tag);
find_replace(/key:\"handleSelect\".*key:\"handleClickTab\",/g, 'key: "handleSelect", value: function(t) {window.location.replace("/?filter=top&duration="+t);}}, {key:"handleClickTab",', a_text); // Top individual durations
find_replace(/this.forceUpdate\(\)\):.*\}\):.\..\.replace/g, 'this.forceUpdate()): window.location.replace("/?filter="+e) :k.a.replace', a_text); // Latest
find_replace(/.\..\.replace.*key:\"handleClose\",/g, 'window.location.replace("/") }}, {key:\"handleClose\",', a_text); // Follow
text = apply_patch(a_text);
}
else{
update_hud(cur_tag+'_led', hud_led.inactive); // Update HUD LED
update_hud(cur_tag, hud_strings.inactive); // Update HUD
}
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.textContent = text;
var head = document.getElementsByTagName('head')[0];
head.appendChild(newScript);
}
window.addEventListener('beforescriptexecute', function(e) {
var src = e.target.src;
//console.log('src: '+src);
if (src.search(/compose.*\.js$/) != -1) {
//console.log('found compose');
e.preventDefault();
e.stopPropagation();
GM_xmlhttpRequest({
method: "GET",
url: e.target.src,
onload: function(response) {
updateCompose(response.responseText);
}
});
}
else if (src.search(/common.*\.js$/) != -1) {
//console.log('found common');
e.preventDefault();
e.stopPropagation();
GM_xmlhttpRequest({
method: "GET",
url: e.target.src,
onload: function(response) {
updateCommon(response.responseText);
}
});
}
else if (src.search(/_app.*\.js$/) != -1) {
//console.log('found app');
e.preventDefault();
e.stopPropagation();
GM_xmlhttpRequest({
method: "GET",
url: e.target.src,
onload: function(response) {
updateApp(response.responseText);
}
});
}
else if (src.search(/settings.*\.js$/) != -1) {
//console.log('found settings');
e.preventDefault();
e.stopPropagation();
GM_xmlhttpRequest({
method: "GET",
url: e.target.src,
onload: function(response) {
updateSettings(response.responseText);
}
});
}
else if (src.search(/index.*\.js$/) != -1) {
//console.log('found index');
e.preventDefault();
e.stopPropagation();
GM_xmlhttpRequest({
method: "GET",
url: e.target.src,
onload: function(response) {
updateIndex(response.responseText);
}
});
}
}, true);
// Vars for HUD
var hud_strings = {loading:'Not yet loaded...', inactive:'Inactive', failed: 'Failure', success: 'Success', force_success: 'Forced success'};
var hud_led = {loading:'
Twetch Tweaks | ► |
Check for Updates... | ❤️ |