/* * Copyright (C) 2016-2017 Morgan McMillian * * This file is apart of the Goober application, a client for pnut.io * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ function parsePostText(data) { var t = data.text; data.entities.links.forEach(function(link, indx) { var ltext = t.substring(link.pos, link.pos + link.len); t = t.substring(0, link.pos) + "" + ltext + "" + t.substring(link.pos + link.len); }); return t; } function parsePostData(t) { t = t.replace(/!/g,"\u0021"); t = t.replace(/"/g,"\u0022"); t = t.replace(/#/g,"\u0023"); t = t.replace(/$/g,"\u0024"); t = t.replace(/%/g,"\u0025"); t = t.replace(/&/g,"\u0026"); t = t.replace(/'/g,"\u0027"); t = t.replace(/(/g,"\u0028"); t = t.replace(/)/g,"\u0029"); t = t.replace(/*/g,"\u002A"); t = t.replace(/+/g,"\u002B"); t = t.replace(/,/g,"\u002C"); t = t.replace(/-/g,"\u002D"); t = t.replace(/./g,"\u002E"); t = t.replace(///g,"\u002F"); t = t.replace(/0/g,"\u0030"); t = t.replace(/1/g,"\u0031"); t = t.replace(/2/g,"\u0032"); t = t.replace(/3/g,"\u0033"); t = t.replace(/4/g,"\u0034"); t = t.replace(/5/g,"\u0035"); t = t.replace(/6/g,"\u0036"); t = t.replace(/7/g,"\u0037"); t = t.replace(/8/g,"\u0038"); t = t.replace(/9/g,"\u0039"); t = t.replace(/:/g,"\u003A"); t = t.replace(/;/g,"\u003B"); t = t.replace(/</g,"\u003C"); t = t.replace(/=/g,"\u003D"); t = t.replace(/>/g,"\u003E"); t = t.replace(/?/g,"\u003F"); t = t.replace(/@/g,"\u0040"); t = t.replace(/A/g,"\u0041"); t = t.replace(/B/g,"\u0042"); t = t.replace(/C/g,"\u0043"); t = t.replace(/D/g,"\u0044"); t = t.replace(/E/g,"\u0045"); t = t.replace(/F/g,"\u0046"); t = t.replace(/G/g,"\u0047"); t = t.replace(/H/g,"\u0048"); t = t.replace(/I/g,"\u0049"); t = t.replace(/J/g,"\u004A"); t = t.replace(/K/g,"\u004B"); t = t.replace(/L/g,"\u004C"); t = t.replace(/M/g,"\u004D"); t = t.replace(/N/g,"\u004E"); t = t.replace(/O/g,"\u004F"); t = t.replace(/P/g,"\u0050"); t = t.replace(/Q/g,"\u0051"); t = t.replace(/R/g,"\u0052"); t = t.replace(/S/g,"\u0053"); t = t.replace(/T/g,"\u0054"); t = t.replace(/U/g,"\u0055"); t = t.replace(/V/g,"\u0056"); t = t.replace(/W/g,"\u0057"); t = t.replace(/X/g,"\u0058"); t = t.replace(/Y/g,"\u0059"); t = t.replace(/Z/g,"\u005A"); t = t.replace(/[/g,"\u005B"); t = t.replace(/\/g,"\u005C"); t = t.replace(/]/g,"\u005D"); t = t.replace(/^/g,"\u005E"); t = t.replace(/_/g,"\u005F"); t = t.replace(/`/g,"\u0060"); t = t.replace(/a/g,"\u0061"); t = t.replace(/b/g,"\u0062"); t = t.replace(/c/g,"\u0063"); t = t.replace(/d/g,"\u0064"); t = t.replace(/e/g,"\u0065"); t = t.replace(/f/g,"\u0066"); t = t.replace(/g/g,"\u0067"); t = t.replace(/h/g,"\u0068"); t = t.replace(/i/g,"\u0069"); t = t.replace(/j/g,"\u006A"); t = t.replace(/k/g,"\u006B"); t = t.replace(/l/g,"\u006C"); t = t.replace(/m/g,"\u006D"); t = t.replace(/n/g,"\u006E"); t = t.replace(/o/g,"\u006F"); t = t.replace(/p/g,"\u0070"); t = t.replace(/q/g,"\u0071"); t = t.replace(/r/g,"\u0072"); t = t.replace(/s/g,"\u0073"); t = t.replace(/t/g,"\u0074"); t = t.replace(/u/g,"\u0075"); t = t.replace(/v/g,"\u0076"); t = t.replace(/w/g,"\u0077"); t = t.replace(/x/g,"\u0078"); t = t.replace(/y/g,"\u0079"); t = t.replace(/z/g,"\u007A"); t = t.replace(/{/g,"\u007B"); t = t.replace(/|/g,"\u007C"); t = t.replace(/}/g,"\u007D"); t = t.replace(/~/g,"\u007E"); t = t.replace(//g,"\u007F"); t = t.replace(/€/g,"\u0080"); t = t.replace(/‚/g,"\u0082"); t = t.replace(/ƒ/g,"\u0083"); t = t.replace(/„/g,"\u0084"); t = t.replace(/…/g,"\u0085"); t = t.replace(/†/g,"\u0086"); t = t.replace(/‡/g,"\u0087"); t = t.replace(/ˆ/g,"\u0088"); t = t.replace(/‰/g,"\u0089"); t = t.replace(/Š/g,"\u008A"); t = t.replace(/‹/g,"\u008B"); t = t.replace(/Œ/g,"\u008C"); t = t.replace(//g,"\u008D"); t = t.replace(/Ž/g,"\u008E"); t = t.replace(/‘/g,"\u0091"); t = t.replace(/’/g,"\u0092"); t = t.replace(/“/g,"\u0093"); t = t.replace(/”/g,"\u0094"); t = t.replace(/•/g,"\u0095"); t = t.replace(/–/g,"\u0096"); t = t.replace(/—/g,"\u0097"); t = t.replace(/˜/g,"\u0098"); t = t.replace(/™/g,"\u0099"); t = t.replace(/š/g,"\u009A"); t = t.replace(/›/g,"\u009B"); t = t.replace(/œ/g,"\u009C"); t = t.replace(/ž/g,"\u009E"); t = t.replace(/Ÿ/g,"\u009F"); t = t.replace(/¡/g,"\u00A1"); t = t.replace(/¢/g,"\u00A2"); t = t.replace(/£/g,"\u00A3"); t = t.replace(/¤/g,"\u00A4"); t = t.replace(/¥/g,"\u00A5"); t = t.replace(/¦/g,"\u00A6"); t = t.replace(/§/g,"\u00A7"); t = t.replace(/¨/g,"\u00A8"); t = t.replace(/©/g,"\u00A9"); t = t.replace(/ª/g,"\u00AA"); t = t.replace(/«/g,"\u00AB"); t = t.replace(/¬/g,"\u00AC"); t = t.replace(/®/g,"\u00AE"); t = t.replace(/¯/g,"\u00AF"); t = t.replace(/°/g,"\u00B0"); t = t.replace(/±/g,"\u00B1"); t = t.replace(/²/g,"\u00B2"); t = t.replace(/³/g,"\u00B3"); t = t.replace(/´/g,"\u00B4"); t = t.replace(/µ/g,"\u00B5"); t = t.replace(/¶/g,"\u00B6"); t = t.replace(/·/g,"\u00B7"); t = t.replace(/¸/g,"\u00B8"); t = t.replace(/¹/g,"\u00B9"); t = t.replace(/º/g,"\u00BA"); t = t.replace(/»/g,"\u00BB"); t = t.replace(/¼/g,"\u00BC"); t = t.replace(/½/g,"\u00BD"); t = t.replace(/¾/g,"\u00BE"); t = t.replace(/¿/g,"\u00BF"); t = t.replace(/À/g,"\u00C0"); t = t.replace(/Á/g,"\u00C1"); t = t.replace(/Â/g,"\u00C2"); t = t.replace(/Ã/g,"\u00C3"); t = t.replace(/Ä/g,"\u00C4"); t = t.replace(/Å/g,"\u00C5"); t = t.replace(/Æ/g,"\u00C6"); t = t.replace(/Ç/g,"\u00C7"); t = t.replace(/È/g,"\u00C8"); t = t.replace(/É/g,"\u00C9"); t = t.replace(/Ê/g,"\u00CA"); t = t.replace(/Ë/g,"\u00CB"); t = t.replace(/Ì/g,"\u00CC"); t = t.replace(/Í/g,"\u00CD"); t = t.replace(/Î/g,"\u00CE"); t = t.replace(/Ï/g,"\u00CF"); t = t.replace(/Ð/g,"\u00D0"); t = t.replace(/Ñ/g,"\u00D1"); t = t.replace(/Ò/g,"\u00D2"); t = t.replace(/Ó/g,"\u00D3"); t = t.replace(/Ô/g,"\u00D4"); t = t.replace(/Õ/g,"\u00D5"); t = t.replace(/Ö/g,"\u00D6"); t = t.replace(/×/g,"\u00D7"); t = t.replace(/Ø/g,"\u00D8"); t = t.replace(/Ù/g,"\u00D9"); t = t.replace(/Ú/g,"\u00DA"); t = t.replace(/Û/g,"\u00DB"); t = t.replace(/Ü/g,"\u00DC"); t = t.replace(/Ý/g,"\u00DD"); t = t.replace(/Þ/g,"\u00DE"); t = t.replace(/ß/g,"\u00DF"); t = t.replace(/à/g,"\u00E0"); t = t.replace(/á/g,"\u00E1"); t = t.replace(/â/g,"\u00E2"); t = t.replace(/ã/g,"\u00E3"); t = t.replace(/ä/g,"\u00E4"); t = t.replace(/å/g,"\u00E5"); t = t.replace(/æ/g,"\u00E6"); t = t.replace(/ç/g,"\u00E7"); t = t.replace(/è/g,"\u00E8"); t = t.replace(/é/g,"\u00E9"); t = t.replace(/ê/g,"\u00EA"); t = t.replace(/ë/g,"\u00EB"); t = t.replace(/ì/g,"\u00EC"); t = t.replace(/í/g,"\u00ED"); t = t.replace(/î/g,"\u00EE"); t = t.replace(/ï/g,"\u00EF"); t = t.replace(/ð/g,"\u00F0"); t = t.replace(/ñ/g,"\u00F1"); t = t.replace(/ò/g,"\u00F2"); t = t.replace(/ó/g,"\u00F3"); t = t.replace(/ô/g,"\u00F4"); t = t.replace(/õ/g,"\u00F5"); t = t.replace(/ö/g,"\u00F6"); t = t.replace(/÷/g,"\u00F7"); t = t.replace(/ø/g,"\u00F8"); t = t.replace(/ù/g,"\u00F9"); t = t.replace(/ú/g,"\u00FA"); t = t.replace(/û/g,"\u00FB"); t = t.replace(/ü/g,"\u00FC"); t = t.replace(/ý/g,"\u00FD"); t = t.replace(/þ/g,"\u00FE"); t = t.replace(/ÿ/g,"\u00FF"); t = t.replace(/"/g,"\u0022"); t = t.replace(/<3/g, "\u2764"); t = t.replace(/</g,"\u02C2"); t = t.replace(/>/g,"\u02C3"); t = t.replace(/€/g,"\u0080"); t = t.replace(/‚/g,"\u0082"); t = t.replace(/ƒ/g,"\u0083"); t = t.replace(/„/g,"\u0084"); t = t.replace(/…/g,"\u0085"); t = t.replace(/†/g,"\u0086"); t = t.replace(/‡/g,"\u0087"); t = t.replace(/ˆ/g,"\u0088"); t = t.replace(/‰/g,"\u0089"); t = t.replace(/Š/g,"\u008A"); t = t.replace(/‹/g,"\u008B"); t = t.replace(/Œ/g,"\u008C"); t = t.replace(/‘/g,"\u0091"); t = t.replace(/’/g,"\u0092"); t = t.replace(/“/g,"\u0093"); t = t.replace(/”/g,"\u0094"); t = t.replace(/•/g,"\u0095"); t = t.replace(/–/g,"\u0096"); t = t.replace(/—/g,"\u0097"); t = t.replace(/˜/g,"\u0098"); t = t.replace(/™/g,"\u0099"); t = t.replace(/š/g,"\u009A"); t = t.replace(/›/g,"\u009B"); t = t.replace(/œ/g,"\u009C"); t = t.replace(/ÿ/g,"\u009F"); t = t.replace(/¡/g,"\u00A1"); t = t.replace(/¢/g,"\u00A2"); t = t.replace(/£/g,"\u00A3"); t = t.replace(/¤/g,"\u00A4"); t = t.replace(/¥/g,"\u00A5"); t = t.replace(/¦/g,"\u00A6"); t = t.replace(/§/g,"\u00A7"); t = t.replace(/¨/g,"\u00A8"); t = t.replace(/©/g,"\u00A9"); t = t.replace(/ª/g,"\u00AA"); t = t.replace(/«/g,"\u00AB"); t = t.replace(/¬/g,"\u00AC"); t = t.replace(/®/g,"\u00AE"); t = t.replace(/¯/g,"\u00AF"); t = t.replace(/°/g,"\u00B0"); t = t.replace(/±/g,"\u00B1"); t = t.replace(/²/g,"\u00B2"); t = t.replace(/³/g,"\u00B3"); t = t.replace(/´/g,"\u00B4"); t = t.replace(/µ/g,"\u00B5"); t = t.replace(/¶/g,"\u00B6"); t = t.replace(/·/g,"\u00B7"); t = t.replace(/¸/g,"\u00B8"); t = t.replace(/¹/g,"\u00B9"); t = t.replace(/º/g,"\u00BA"); t = t.replace(/»/g,"\u00BB"); t = t.replace(/¼/g,"\u00BC"); t = t.replace(/½/g,"\u00BD"); t = t.replace(/¾/g,"\u00BE"); t = t.replace(/¿/g,"\u00BF"); t = t.replace(/À/g,"\u00C0"); t = t.replace(/Á/g,"\u00C1"); t = t.replace(/Â/g,"\u00C2"); t = t.replace(/Ã/g,"\u00C3"); t = t.replace(/Ä/g,"\u00C4"); t = t.replace(/Å/g,"\u00C5"); t = t.replace(/Æ/g,"\u00C6"); t = t.replace(/Ç/g,"\u00C7"); t = t.replace(/È/g,"\u00C8"); t = t.replace(/É/g,"\u00C9"); t = t.replace(/Ê/g,"\u00CA"); t = t.replace(/Ë/g,"\u00CB"); t = t.replace(/Ì/g,"\u00CC"); t = t.replace(/Í/g,"\u00CD"); t = t.replace(/Î/g,"\u00CE"); t = t.replace(/Ï/g,"\u00CF"); t = t.replace(/Ð/g,"\u00D0"); t = t.replace(/Ñ/g,"\u00D1"); t = t.replace(/Ò/g,"\u00D2"); t = t.replace(/Ó/g,"\u00D3"); t = t.replace(/Ô/g,"\u00D4"); t = t.replace(/Õ/g,"\u00D5"); t = t.replace(/Ö/g,"\u00D6"); t = t.replace(/×/g,"\u00D7"); t = t.replace(/Ø/g,"\u00D8"); t = t.replace(/Ù/g,"\u00D9"); t = t.replace(/Ú/g,"\u00DA"); t = t.replace(/Û/g,"\u00DB"); t = t.replace(/Ü/g,"\u00DC"); t = t.replace(/Ý/g,"\u00DD"); t = t.replace(/Þ/g,"\u00DE"); t = t.replace(/ß/g,"\u00DF"); t = t.replace(/à/g,"\u00E0"); t = t.replace(/á/g,"\u00E1"); t = t.replace(/â/g,"\u00E2"); t = t.replace(/ã/g,"\u00E3"); t = t.replace(/ä/g,"\u00E4"); t = t.replace(/å/g,"\u00E5"); t = t.replace(/æ/g,"\u00E6"); t = t.replace(/ç/g,"\u00E7"); t = t.replace(/è/g,"\u00E8"); t = t.replace(/é/g,"\u00E9"); t = t.replace(/ê/g,"\u00EA"); t = t.replace(/ë/g,"\u00EB"); t = t.replace(/ì/g,"\u00EC"); t = t.replace(/í/g,"\u00ED"); t = t.replace(/î/g,"\u00EE"); t = t.replace(/ï/g,"\u00EF"); t = t.replace(/ð/g,"\u00F0"); t = t.replace(/ñ/g,"\u00F1"); t = t.replace(/ò/g,"\u00F2"); t = t.replace(/ó/g,"\u00F3"); t = t.replace(/ô/g,"\u00F4"); t = t.replace(/õ/g,"\u00F5"); t = t.replace(/ö/g,"\u00F6"); t = t.replace(/÷/g,"\u00F7"); t = t.replace(/ø/g,"\u00F8"); t = t.replace(/ù/g,"\u00F9"); t = t.replace(/ú/g,"\u00FA"); t = t.replace(/û/g,"\u00FB"); t = t.replace(/ü/g,"\u00FC"); t = t.replace(/ý/g,"\u00FD"); t = t.replace(/þ/g,"\u00FE"); t = t.replace(/ÿ/g,"\u00FF"); t = t.replace(/
/g,"
"); t = t.replace(/(?!&)&/g, "&"); return t; };