index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * FeHelper 进制转换工具
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. fromArray: [2, 4, 8, 10, 16],
  8. fromSelected: 10,
  9. toArray: [2, 4, 8, 10, 16],
  10. toSelected: 16,
  11. srcValue: 100,
  12. rstValue: 0
  13. },
  14. mounted: function () {
  15. // 进制转换的初始化
  16. this.radixConvert();
  17. },
  18. methods: {
  19. loadPatchHotfix() {
  20. // 页面加载时自动获取并注入页面的补丁
  21. chrome.runtime.sendMessage({
  22. type: 'fh-dynamic-any-thing',
  23. thing: 'fh-get-tool-patch',
  24. toolName: 'trans-radix'
  25. }, patch => {
  26. if (patch) {
  27. if (patch.css) {
  28. const style = document.createElement('style');
  29. style.textContent = patch.css;
  30. document.head.appendChild(style);
  31. }
  32. if (patch.js) {
  33. try {
  34. if (window.evalCore && window.evalCore.getEvalInstance) {
  35. window.evalCore.getEvalInstance(window)(patch.js);
  36. }
  37. } catch (e) {
  38. console.error('trans-radix补丁JS执行失败', e);
  39. }
  40. }
  41. }
  42. });
  43. },
  44. getId: (type, id) => [type, id].join('_'),
  45. switchInput: function () {
  46. [this.fromSelected, this.toSelected] = [this.toSelected, this.fromSelected];
  47. [this.srcValue, this.rstValue] = [this.rstValue, this.srcValue];
  48. },
  49. radixRadioClicked: function (type, n) {
  50. if (type === 1) {
  51. this.fromSelected = n;
  52. } else {
  53. this.toSelected = n;
  54. }
  55. this.radixConvert();
  56. },
  57. radixConvert: function () {
  58. this.$nextTick(() => {
  59. this.rstValue = parseInt(this.srcValue, this.fromSelected).toString(this.toSelected);
  60. });
  61. },
  62. openDonateModal: function(event) {
  63. event.preventDefault();
  64. event.stopPropagation();
  65. chrome.runtime.sendMessage({
  66. type: 'fh-dynamic-any-thing',
  67. thing: 'open-donate-modal',
  68. params: { toolName: 'trans-radix' }
  69. });
  70. },
  71. openOptionsPage: function(event) {
  72. event.preventDefault();
  73. event.stopPropagation();
  74. chrome.runtime.openOptionsPage();
  75. }
  76. }
  77. });