BradinDvorak

CYS Advanced Names

May 21st, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. # Naming Page
  2.  
  3. Add one "Accept" link that leads to the next page.
  4.  
  5. ```
  6. <input id="playerName" type="text">
  7. ```
  8.  
  9. # Naming Page "Accept" Link Script
  10.  
  11. Return to the naming page if the first digit is empty.
  12.  
  13. ```
  14. IF %N0 = 0 THEN $DEST := @NONE
  15. ```
  16.  
  17. # Subsequent Pages
  18.  
  19. To insert the name into the story, use `$$NAME$$`.
  20.  
  21. # Global Page Script
  22.  
  23. IDK I might change some stuff later. Some of the variables can be changed to fit your game; they're the ones with comments next to them.
  24.  
  25. ```
  26. $PAGETEXT := "<script>
  27. // Polyfills
  28. 'function'!=typeof Object.assign&&Object.defineProperty(Object,'assign',{value:function(t,e){'use strict';if(null==t)throw new TypeError('Cannot convert undefined or null to object');for(var r=Object(t),n=1;n<arguments.length;n++){var o=arguments[n];if(null!=o)for(var c in o)Object.prototype.hasOwnProperty.call(o,c)&&(r[c]=o[c])}return r},writable:!0,configurable:!0}),Object.keys||(Object.keys=function(){'use strict';var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable('toString'),r=['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor'],n=r.length;return function(o){if('function'!=typeof o&&('object'!=typeof o||null===o))throw new TypeError('Object.keys called on non-object');var c,i,l=[];for(c in o)t.call(o,c)&&l.push(c);if(e)for(i=0;i<n;i++)t.call(o,r[i])&&l.push(r[i]);return l}}()),Object.entries||(Object.entries=function(t){for(var e=Object.keys(t),r=e.length,n=new Array(r);r--;)n[r]=[e[r],t[e[r]]];return n}),void 0===RegExp.prototype.flags&&Object.defineProperty(RegExp.prototype,'flags',{configurable:!0,get:function(){return this.toString().match(/[gimuy]*$/)[0]}});
  29. </script><script>
  30. var filter = /^[-']|[^-'a-zA-Z\xc0-\xd6\xd8-\xf6\xf8-\xff]/, // the regex defining what to filter out of the name (can be set to null for no filter)
  31. input = 'playerName', // id of the <input> element
  32. length = 12, // max length of the name
  33. playerName = '',
  34. prefix = 'N', // prefix of the name variables (must begin with [A-Z])
  35. regex = /\$\$NAME\$\$/i, // the regex to be replaced with the name
  36. ss = [],
  37. ssVariables = {};
  38.  
  39. document.addEventListener('DOMContentLoaded', function() {
  40. var globalFilter = filter instanceof RegExp ? new RegExp(filter.source, filter.flags.replace(/g|^/i, 'g')) : null,
  41. globalRegex = new RegExp(regex.source, regex.flags.replace(/g|^/i, 'g')),
  42. nameInput = document.querySelector('input#' + input);
  43. ss = atob(document.querySelector('input[name=\'SS\']').value).split('|');
  44. ssVariables = JSON.parse('{' + ss.pop().replace(/[A-Z][A-Z0-9]*/g, '\42$&\42').replace(/,/g, ':').replace(/;/g, ',') + '}');
  45.  
  46. for (var i = 0; i < length; i++) {
  47. var code = ssVariables[prefix + i];
  48. if (code) playerName += String.fromCharCode(code);
  49. }
  50.  
  51. if (nameInput) {
  52. nameInput.maxLength = length;
  53. nameInput.addEventListener('input', function() {
  54. var obj = {},
  55. val = this.value;
  56. if (filter) this.value = val = val.replace(filter, '');
  57. for (var i = 0; i < length; i++) {
  58. obj[prefix + i] = val.charCodeAt(i) || 0;
  59. }
  60. updateVariables(obj);
  61. });
  62. }
  63.  
  64. var names = [].slice.call(document.querySelectorAll('.dark1border + div > div, .dark1border + div > div *')).reduce(function(a, e) {
  65. return a.concat([].slice.call(e.childNodes))
  66. }, []).filter(function(e) {
  67. return (e.nodeType == 3 && e.nodeValue.trim() && regex.test(e.data))
  68. });
  69. for (var i = 0; i < names.length; i++) {
  70. var div = document.createElement('div'),
  71. node = names[i];
  72. div.innerHTML = node.data.replace(globalRegex, playerName);
  73. while (div.firstChild) {
  74. node.parentNode.insertBefore(div.firstChild, node);
  75. }
  76. node.parentNode.removeChild(node);
  77. }
  78. });
  79.  
  80. updateVariables = function(obj) {
  81. Object.assign(ssVariables, obj);
  82. }
  83.  
  84. applySS = function() {
  85. document.querySelector('input[name=\'SS\']').value = btoa(
  86. ss.concat(Object.entries(ssVariables).map(function(e) {
  87. return e.join(',');
  88. }).join(';'))
  89. .join('|'));
  90. }
  91.  
  92. PostBack = function(action, value) {
  93. applySS();
  94. var frm = getEl('pbForm');
  95. frm.pbAction.value = action ? action : '';
  96. frm.pbValue.value = value ? value : '';
  97. frm.submit();
  98. return false;
  99. }
  100. </script>" + $PAGETEXT
  101. ```
Add Comment
Please, Sign In to add comment