Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var colors = [
- "#e6b8af", "#f4cccc", "#fce5cd", "#fff2cc", "#d9ead3",
- "#d0e0e3", "#c9daf8", "#cfe2f3", "#d9d2e9", "#ead1dc",
- "#dd7e6b", "#ea9999", "#f9cb9c", "#ffe599", "#b6d7a8",
- "#a2c4c9", "#a4c2f4", "#9fc5e8", "#b4a7d6", "#d5a6bd",
- "#cc4125", "#e06666", "#f6b26b", "#ffd966", "#93c47d",
- "#76a5af", "#6d9eeb", "#6fa8dc", "#8e7cc3", "#c27ba0"
- ];
- var attentionColors = ['#00ffff', '#ff00ff', '#800080'];
- function groupValues(values) {
- return values.reduce(function(acc, row, index) {
- var bid = Bid(row, index);
- if (bid.carName === '') {
- acc.push([]);
- } else {
- acc[acc.length - 1].push(bid);
- }
- return acc;
- }, [[]])
- .filter(function(row) {
- return row.length;
- })
- .map(function(group) {
- return Group(group);
- });
- }
- function Bid(row, index) {
- return {
- index: index,
- bidType: row[1],
- carName: row[2],
- yesNo: row[3],
- buyer: row[4].split(' ')[0] || '',
- bid: row[4].split(' ')[1] || null,
- wantsToBuy: +row[5],
- additional: row[6]
- };
- }
- function Group(bids) {
- return {
- buyer: bids[0].buyer,
- wantsToBuy: bids[0].wantsToBuy,
- bids: bids,
- hasActive: bids.some(function(bid) { return bid.bidType === '!'; })
- };
- }
- function colorRows(groups, sheet) {
- var groupColor = 0;
- groups.forEach(function(group) {
- if (group.wantsToBuy !== 0) {
- group.bids.forEach(function(row) {
- if (group.hasActive) {
- return;
- }
- var range = sheet.getRange(row.index + 1, 3);
- var isAttentionColor = (function() {
- var background = range.getBackground();
- return attentionColors.some(function(color) {
- return color === background;
- });
- })();
- if (isAttentionColor) {
- return;
- }
- range.setBackground('none');
- range.setBackground(colors[groupColor]);
- });
- groupColor = (groupColor + 1) % colors.length;
- }
- });
- }
- function highlight() {
- var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
- var sheets = spreadsheet.getSheets();
- sheets.forEach(function(sheet) {
- var dataRange = sheet.getDataRange();
- var values = dataRange.getValues();
- var groups = groupValues(values);
- colorRows(groups, sheet);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement