Guest User

Untitled

a guest
Jan 12th, 2021
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. console.log("Loading anchor addon");
  3. var editOps = require('../engine/modOps/editOps');
  4. var staticManipulator = require('../engine/domManipulator/static');
  5. var templatehandler = require('../engine/templateHandler');
  6. var db = require('../db');
  7.  
  8. exports.init = function() {
  9.  
  10.  
  11. var threads = db.threads();
  12.  
  13. var changed_func = function(parameters, thread, callback) {
  14. parameters.lock = !!parameters.lock;
  15. parameters.pin = !!parameters.pin;
  16. parameters.cyclic = !!parameters.cyclic;
  17. parameters.autoSage = !!parameters.autoSage; //added this
  18.  
  19. var changePin = parameters.pin !== thread.pinned;
  20. var changeLock = parameters.lock !== thread.locked;
  21. var changeCyclic = parameters.cyclic !== thread.cyclic;
  22. var changeAutoSage = parameters.autoSage !== thread.autoSage; //added this
  23.  
  24. if (!changeLock && !changePin && !changeCyclic && !changeAutoSage/*added this*/) {
  25. callback();
  26.  
  27. return;
  28. }
  29.  
  30. threads.updateOne({
  31. _id : thread._id
  32. }, {
  33. $set : {
  34. locked : parameters.lock,
  35. pinned : parameters.pin,
  36. cyclic : parameters.cyclic,
  37. autoSage : parameters.autoSage && !parameters.cyclic //changed this from //thread.autoSage && !parameters.cyclic
  38. },
  39. $unset : {
  40. innerCache : 1,
  41. outerCache : 1,
  42. previewCache : 1,
  43. clearCache : 1,
  44. alternativeCaches : 1,
  45. hashedCache : 1
  46. }
  47. }, function updatedThread(error) {
  48.  
  49. if (!error) {
  50. // signal rebuild of thread
  51. process.send({
  52. board : thread.boardUri,
  53. thread : thread.threadId
  54. });
  55.  
  56. if (changePin) {
  57.  
  58. // signal rebuild of board pages
  59. postOps.setThreadsPage(thread.boardUri, function(errr) {
  60. if (error) {
  61. console.log(error);
  62. } else {
  63. process.send({
  64. board : thread.boardUri
  65. });
  66. }
  67. });
  68.  
  69. } else {
  70. // signal rebuild of page
  71. process.send({
  72. board : thread.boardUri,
  73. page : thread.page
  74. });
  75. }
  76.  
  77. }
  78.  
  79. callback(error);
  80.  
  81. });
  82. };
  83.  
  84. editOps.setNewThreadSettings = changed_func;
  85.  
  86. var original_domanipulator = staticManipulator.setModdingInformation;
  87.  
  88. staticManipulator.setModdingInformation = function(document, threadData){
  89. if (threadData.autoSage) {
  90. console.log(document)
  91. document = document.replace('__checkboxAutoSage_checked__', 'true');
  92. } else {
  93. document = document.replace('checked="__checkboxAutoSage_checked__"', '');
  94. }
  95. return original_domanipulator(document, threadData);
  96. }
  97.  
  98. templatehandler.pageTests[10]["prebuiltFields"]["checkboxAutoSage"]= "checked";
  99.  
  100.  
  101. console.log("Loaded anchor addon");
  102. };
  103.  
  104.  
RAW Paste Data