Advertisement
Guest User

Untitled

a guest
Aug 28th, 2018
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onOpen() {
  2.   DocumentApp.getUi()
  3.       .createMenu('Utilities')
  4.       .addItem('Auto-Replace', 'replaceSuits')
  5.       .addToUi();
  6. };
  7.  
  8. function replaceSuits() {
  9.   var body = DocumentApp.getActiveDocument().getBody();
  10.   var text = body.editAsText();
  11.  
  12.  
  13.   var found = body.findText("♥");
  14.   while (found) {
  15.     var elem = found.getElement();
  16.     if (found.isPartial()) {
  17.       var start = found.getStartOffset();
  18.       var end = found.getEndOffsetInclusive();
  19.       elem.setBackgroundColor(start, end, "#ff0000");
  20.     }
  21.     else {
  22.       elem.setBackgroundColor("#ff0000");
  23.     }
  24.     found = body.findText("♥", found);
  25.   }
  26.  
  27.   found = body.findText("♦");
  28.   while (found) {
  29.     var elem = found.getElement();
  30.     if (found.isPartial()) {
  31.       var start = found.getStartOffset();
  32.       var end = found.getEndOffsetInclusive();
  33.       elem.setBackgroundColor(start, end, "#ffa500");
  34.     }
  35.     else {
  36.       elem.setBackgroundColor("#ffa500");
  37.     }
  38.     found = body.findText("♦", found);
  39.   }
  40.  
  41.   found = body.findText("♣");
  42.   while (found) {
  43.     var elem = found.getElement();
  44.     if (found.isPartial()) {
  45.       var start = found.getStartOffset();
  46.       var end = found.getEndOffsetInclusive();
  47.       elem.setBackgroundColor(start, end, "#008000");
  48.     }
  49.     else {
  50.       elem.setBackgroundColor("#008000");
  51.     }
  52.     found = body.findText("♣", found);
  53.   }
  54.  
  55.   found = body.findText("♠");
  56.   while (found) {
  57.     var elem = found.getElement();
  58.     if (found.isPartial()) {
  59.       var start = found.getStartOffset();
  60.       var end = found.getEndOffsetInclusive();
  61.       elem.setBackgroundColor(start, end, "#0000ff");
  62.     }
  63.     else {
  64.       elem.setBackgroundColor("#0000ff");
  65.     }
  66.     found = body.findText("♠", found);
  67.   }
  68. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement