<commit_before>import add from './support/task';
import createDocument from './system/createDocument';
import {createInput} from './common/cElement';
import {getElementById} from './common/getElement';
import getMembrList from './ajax/getMembrList';
import getValue from './system/getValue';
import insertElement from './common/insertElement';
import insertHtmlAfterBegin from './common/insertHtmlAfterBegin';
import insertHtmlBeforeEnd from './common/insertHtmlBeforeEnd';
import jQueryNotPresent from './common/jQueryNotPresent';
import moreToDo from './common/moreToDo';
import {pCC} from './support/layout';
import playerName from './common/playerName';
import retryAjax from './ajax/retryAjax';

var ranks;
var myRank;
var theRows;
var rankCount;
var characterRow;

var privLookup = {
  'Bank Withdraw': 5,
  'Build/Upgrade/Demolish Structures': 5,
  'Can Un-Tag Items': 5,
  'Build/Upgrade Structures': 4,
  'Can Kick Members': 4,
  'Can Mass Messages': 0.5,
  'Take Items': 0.2,
  'Can Recall Tagged Items': 0.2,
  'Store Items': 0.1,
  'Can View Advisor': 0.1
};

function parseRankData(linkElement, responseText) {
  // Makes a weighted calculation of available permissions and gets tax rate
  var doc = createDocument(responseText);
  var checkBoxes = doc.querySelectorAll(
    '#pCC input[type="checkbox"]:checked');
  var count = 0;
  Array.prototype.forEach.call(checkBoxes, function(checkbox) {
    var privName = checkbox.nextElementSibling.textContent.trim();
    if (privName in privLookup) {
      count += privLookup[privName];
    } else {count += 1;}
  });
  var taxRate = doc.querySelector('#pCC input[name="rank_tax"]').value;
  insertHtmlAfterBegin(linkElement, '<span class="fshBlue">(' +
    Math.round(10 * count) / 10 + ') Tax:(' + taxRate + '%)</span> ');
}

function fetchRankData() { // jQuery.min
  var calcButton = getElementById('getrankweightings');
  calcButton.classList.add('fshHide');
  var allItems = document.querySelectorAll('#pCC input[value="Edit"]');
  Array.prototype.forEach.call(allItems, function(anItem) {
    var targetNode = anItem.parentNode.parentNode.previousElementSibling;
    var href = /window\.location='(.*)';/.exec(anItem
      .getAttribute('onclick'))[1];
    retryAjax(href).done(parseRankData.bind(null, targetNode));
  });
}

function notValidRow(thisRankRowNum, targetRowNum, parentTable) {
  return characterRow >= Math.min(thisRankRowNum, targetRowNum) ||
    targetRowNum < 1 ||
    targetRowNum > parentTable.rows.length;
}

function getTargetRowNumber(val) {
  if (val === 'Up') {return -1;}
  return 2;
}

function getPxScroll(val) {
  if (val === 'Up') {return -22;}
  return 22;
}

function overrideUpDown(evt, val) {
  var onclickHREF = /window.location='(.*)';/
    .exec(evt.target.getAttribute('onclick'))[1];
  var thisRankRow = evt.target.parentNode.parentNode.parentNode;
  var thisRankRowNum = thisRankRow.rowIndex;
  var targetRowNum = thisRankRowNum + getTargetRowNumber(val);
  var parentTable = thisRankRow.parentNode;
  if (notValidRow(thisRankRowNum, targetRowNum, parentTable)) {return;}
  retryAjax(onclickHREF);
  var injectRow = parentTable.rows[targetRowNum];
  parentTable.insertBefore(thisRankRow, injectRow);
  var pxScroll = getPxScroll(val);
  window.scrollBy(0, pxScroll);
  evt.stopPropagation();
}

function ajaxifyRankControls(evt) {
  var val = evt.target.getAttribute('value');
  if (val === 'Up' || val === 'Down') {overrideUpDown(evt, val);}
}

function doButtons() {
  // gather rank info button
  var founder = getElementById('show-guild-founder-rank-name');
  if (founder) {
    var weightButton = createInput({
      id: 'getrankweightings',
      className: 'custombutton',
      type: 'button',
      value: 'Get Rank Weightings'
    });
    weightButton.addEventListener('click', fetchRankData);
    var theTd = founder.parentNode;
    insertHtmlBeforeEnd(theTd, '&nbsp;');
    insertElement(theTd, weightButton);
  }
  // var theTd = getElementById('show-guild-founder-rank-name') // TODO why wouldn't you be able to see this?
  //   .parentNode;

  if (getValue('ajaxifyRankControls')) {
    pCC.addEventListener('click',
      ajaxifyRankControls, true);
  }
}

function isMyRank(rankName) {
  if (rankName === myRank) {
    characterRow = rankCount; // limit for ajaxify later
  }<commit_msg>rank weightings button new layout<commit_after>import add from './support/task';
import createDocument from './system/createDocument';
import {createInput} from './common/cElement';
import {getElementById} from './common/getElement';
import getMembrList from './ajax/getMembrList';
import getValue from './system/getValue';
import insertElement from './common/insertElement';
import insertHtmlAfterBegin from './common/insertHtmlAfterBegin';
import insertHtmlBeforeEnd from './common/insertHtmlBeforeEnd';
import jQueryNotPresent from './common/jQueryNotPresent';
import moreToDo from './common/moreToDo';
import {pCC} from './support/layout';
import playerName from './common/playerName';
import retryAjax from './ajax/retryAjax';

var ranks;
var myRank;
var theRows;
var rankCount;
var characterRow;

var privLookup = {
  'Bank Withdraw': 5,
  'Build/Upgrade/Demolish Structures': 5,
  'Can Un-Tag Items': 5,
  'Build/Upgrade Structures': 4,
  'Can Kick Members': 4,
  'Can Mass Messages': 0.5,
  'Take Items': 0.2,
  'Can Recall Tagged Items': 0.2,
  'Store Items': 0.1,
  'Can View Advisor': 0.1
};

function parseRankData(linkElement, responseText) {
  // Makes a weighted calculation of available permissions and gets tax rate
  var doc = createDocument(responseText);
  var checkBoxes = doc.querySelectorAll(
    '#pCC input[type="checkbox"]:checked');
  var count = 0;
  Array.prototype.forEach.call(checkBoxes, function(checkbox) {
    var privName = checkbox.nextElementSibling.textContent.trim();
    if (privName in privLookup) {
      count += privLookup[privName];
    } else {count += 1;}
  });
  var taxRate = doc.querySelector('#pCC input[name="rank_tax"]').value;
  insertHtmlAfterBegin(linkElement, '<span class="fshBlue">(' +
    Math.round(10 * count) / 10 + ') Tax:(' + taxRate + '%)</span> ');
}

function fetchRankData() { // jQuery.min
  var calcButton = getElementById('getrankweightings');
  calcButton.classList.add('fshHide');
  var allItems = document.querySelectorAll('#pCC input[value="Edit"]');
  Array.prototype.forEach.call(allItems, function(anItem) {
    var targetNode = anItem.parentNode.parentNode.previousElementSibling;
    var href = /window\.location='(.*)';/.exec(anItem
      .getAttribute('onclick'))[1];
    retryAjax(href).done(parseRankData.bind(null, targetNode));
  });
}

function notValidRow(thisRankRowNum, targetRowNum, parentTable) {
  return characterRow >= Math.min(thisRankRowNum, targetRowNum) ||
    targetRowNum < 1 ||
    targetRowNum > parentTable.rows.length;
}

function getTargetRowNumber(val) {
  if (val === 'Up') {return -1;}
  return 2;
}

function getPxScroll(val) {
  if (val === 'Up') {return -22;}
  return 22;
}

function overrideUpDown(evt, val) {
  var onclickHREF = /window.location='(.*)';/
    .exec(evt.target.getAttribute('onclick'))[1];
  var thisRankRow = evt.target.parentNode.parentNode.parentNode;
  var thisRankRowNum = thisRankRow.rowIndex;
  var targetRowNum = thisRankRowNum + getTargetRowNumber(val);
  var parentTable = thisRankRow.parentNode;
  if (notValidRow(thisRankRowNum, targetRowNum, parentTable)) {return;}
  retryAjax(onclickHREF);
  var injectRow = parentTable.rows[targetRowNum];
  parentTable.insertBefore(thisRankRow, injectRow);
  var pxScroll = getPxScroll(val);
  window.scrollBy(0, pxScroll);
  evt.stopPropagation();
}

function ajaxifyRankControls(evt) {
  var val = evt.target.getAttribute('value');
  if (val === 'Up' || val === 'Down') {overrideUpDown(evt, val);}
}

function doButtons() {
  // gather rank info button
  var addNewRank = document.querySelector('#pCC a[href*="=ranks&subcmd2=add"]');
  if (addNewRank) {
    var weightButton = createInput({
      id: 'getrankweightings',
      className: 'custombutton',
      type: 'button',
      value: 'Get Rank Weightings'
    });
    weightButton.addEventListener('click', fetchRankData);
    var theTd = addNewRank.parentNode.parentNode;
    insertHtmlBeforeEnd(theTd, '&nbsp;');
    insertElement(theTd, weightButton);
  }
  if (getValue('ajaxifyRankControls')) {
    pCC.addEventListener('click',
      ajaxifyRankControls, true);
  }
}

function isMyRank(rankName) {
  if (rankName === myRank) {
    characterRow = rankCount; // limit for ajaxify later
  }
{'fraction_non_alphanumeric': 0.14312463428905792, 'fraction_numerical': 0.0073727325921591575, 'mean_word_length': 4.663353214049039, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1262351', 'n_tokens_mistral': 2726, 'n_tokens_neox': 2716, 'n_words': 630}