index.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * FeHelper 信息编解码
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. selectedType: 'uniEncode',
  8. sourceContent: '',
  9. resultContent: ''
  10. },
  11. mounted: function () {
  12. let MSG_TYPE = Tarp.require('../static/js/msg_type');
  13. // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
  14. chrome.runtime.onMessage.addListener((request, sender, callback) => {
  15. if (request.type === MSG_TYPE.TAB_CREATED_OR_UPDATED && request.event === MSG_TYPE.EN_DECODE) {
  16. if (request.content) {
  17. this.sourceContent = request.content;
  18. this.convert();
  19. }
  20. }
  21. });
  22. this.$refs.srcText.focus();
  23. },
  24. methods: {
  25. convert: function () {
  26. this.$nextTick(() => {
  27. let tools = Tarp.require('./endecode-lib');
  28. if (this.selectedType === 'uniEncode') {
  29. this.resultContent = tools.uniEncode(this.sourceContent);
  30. } else if (this.selectedType === 'uniDecode') {
  31. this.resultContent = tools.uniDecode(this.sourceContent.replace(/\\U/g, '\\u'));
  32. } else if (this.selectedType === 'utf8Encode') {
  33. this.resultContent = encodeURIComponent(this.sourceContent);
  34. } else if (this.selectedType === 'utf8Decode') {
  35. this.resultContent = decodeURIComponent(this.sourceContent);
  36. } else if (this.selectedType === 'utf16Encode') {
  37. this.resultContent = tools.utf8to16(encodeURIComponent(this.sourceContent));
  38. } else if (this.selectedType === 'utf16Decode') {
  39. this.resultContent = decodeURIComponent(tools.utf16to8(this.sourceContent));
  40. } else if (this.selectedType === 'base64Encode') {
  41. this.resultContent = tools.base64Encode(tools.utf8Encode(this.sourceContent));
  42. } else if (this.selectedType === 'base64Decode') {
  43. this.resultContent = tools.utf8Decode(tools.base64Decode(this.sourceContent));
  44. } else if (this.selectedType === 'md5Encode') {
  45. this.resultContent = tools.md5(this.sourceContent);
  46. } else if (this.selectedType === 'hexEncode') {
  47. this.resultContent = tools.hexEncode(this.sourceContent);
  48. } else if (this.selectedType === 'hexDecode') {
  49. this.resultContent = tools.hexDecode(this.sourceContent);
  50. }else if (this.selectedType === 'gzipEncode') {
  51. this.resultContent = tools.gzipEncode(this.sourceContent);
  52. } else if (this.selectedType === 'gzipDecode') {
  53. this.resultContent = tools.gzipDecode(this.sourceContent);
  54. } else if (this.selectedType === 'html2js') {
  55. this.resultContent = tools.html2js(this.sourceContent);
  56. }
  57. });
  58. },
  59. clear: function() {
  60. this.sourceContent = '';
  61. this.resultContent = '';
  62. },
  63. getResult: function () {
  64. this.$refs.rstCode.select();
  65. }
  66. }
  67. });