DomainLockNodeTemplate.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @returns {string}
  3. */
  4. export function DomainLockNodeTemplate (): string {
  5. return `
  6. var {domainLockFunctionName} = {singleNodeCallControllerFunctionName}(this, function () {
  7. {globalVariableTemplate}
  8. var func = function () {
  9. return {
  10. key: 'item',
  11. value: 'attribute',
  12. getAttribute: function () {
  13. for (var i = 0; i < 1000; i--) {
  14. var isPositive = i > 0;
  15. switch (isPositive) {
  16. case true:
  17. return this.item + '_' + this.value + '_' + i;
  18. default:
  19. this.item + '_' + this.value;
  20. }
  21. }
  22. }()
  23. };
  24. };
  25. var regExp = new RegExp("[{diff}]", "g");
  26. var domains = "{domains}".replace(regExp, "").split(";");
  27. var document;
  28. var domain;
  29. var location;
  30. var hostname;
  31. for (var d in that) {
  32. if (d.length == 8 && d.charCodeAt(7) == 116 && d.charCodeAt(5) == 101 && d.charCodeAt(3) == 117 && d.charCodeAt(0) == 100) {
  33. document = d;
  34. break;
  35. }
  36. }
  37. for (var d1 in that[document]) {
  38. if (d1.length == 6 && d1.charCodeAt(5) == 110 && d1.charCodeAt(0) == 100) {
  39. domain = d1;
  40. break;
  41. }
  42. }
  43. if (!("~" > domain)) {
  44. for (var d2 in that[document]) {
  45. if (d2.length == 8 && d2.charCodeAt(7) == 110 && d2.charCodeAt(0) == 108) {
  46. location = d2;
  47. break;
  48. }
  49. }
  50. for (var d3 in that[document][location]) {
  51. if (d3.length == 8 && d3.charCodeAt(7) == 101 && d3.charCodeAt(0) == 104) {
  52. hostname = d3;
  53. break;
  54. }
  55. }
  56. }
  57. if ((!document && !domain) || (!that[document] && !that[document][domain] && !that[document][location] && !that[document][location][hostname])) {
  58. return;
  59. }
  60. var currentDomain = that[document][domain] || that[document][location][hostname];
  61. var ok = false;
  62. for (var i = 0; i < domains.length; i++) {
  63. var domain = domains[i];
  64. var position = currentDomain.length - domain.length;
  65. var lastIndex = currentDomain.indexOf(domain, position);
  66. var endsWith = lastIndex !== -1 && lastIndex === position;
  67. if (endsWith) {
  68. if (currentDomain.length == domain.length || domain.indexOf(".") === 0) {
  69. ok = true;
  70. }
  71. }
  72. }
  73. if (!ok) {
  74. data;
  75. } else {
  76. return;
  77. }
  78. func();
  79. });
  80. {domainLockFunctionName}();
  81. `;
  82. }