• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Changes

Jump to navigation Jump to search
no edit summary
Line 11,089: Line 11,089:  
     const day = $(table).data('day')
 
     const day = $(table).data('day')
 
     const time = $(table).data('time')
 
     const time = $(table).data('time')
     $(table).find('tbody tr').each((_, row) => {
+
     $(table)
      const cells = $(row).find('td')
+
      .find('tbody tr')
      rows.push({
+
      .each((_, row) => {
        year: year,
+
        const cells = $(row).find('td')
        month: month,
+
        rows.push({
        day: day,
+
          year: year,
        time: time,
+
          month: month,
        no: parseInt($(cells[0]).text().trim()),
+
          day: day,
        name: $(cells[1]).text().trim().match(/(.*) /)[1],
+
          time: time,
        name_ja: $(cells[1]).text().trim().match(/ \((.*)\)/)[1],
+
          no: parseInt(
        t1: parseInt($(cells[2]).text()),
+
            $(cells[0])
        t5: parseInt($(cells[3]).text()),
+
              .text()
        t20: parseInt($(cells[4]).text()),
+
              .trim(),
        t100: parseInt($(cells[5]).text()),
+
          ),
        t500: parseInt($(cells[6]).text())
+
          name: $(cells[1])
 +
            .text()
 +
            .trim()
 +
            .match(/(.*) /)[1],
 +
          name_ja: $(cells[1])
 +
            .text()
 +
            .trim()
 +
            .match(/ \((.*)\)/)[1],
 +
          t1: parseInt($(cells[2]).text()),
 +
          t5: parseInt($(cells[3]).text()),
 +
          t20: parseInt($(cells[4]).text()),
 +
          t100: parseInt($(cells[5]).text()),
 +
          t500: parseInt($(cells[6]).text()),
 +
        })
 
       })
 
       })
    })
   
   })
 
   })
 
   return rows
 
   return rows
Line 11,112: Line 11,124:  
// Generate CSV from parsed rows.
 
// Generate CSV from parsed rows.
 
const genCSV = rows =>
 
const genCSV = rows =>
   rows.map(row =>
+
   rows
    [row.year, row.month, row.day, row.time, row.no, row.name, row.name_ja, row.t1 || '', row.t5 || '', row.t20 || '', row.t100 || '', row.t500 || '']
+
    .map(row =>
       .join(',')
+
      [
  ).join('\n')
+
        row.year,
 +
        row.month,
 +
        row.day,
 +
        row.time,
 +
        row.no,
 +
        row.name,
 +
        row.name_ja,
 +
        row.t1 || '',
 +
        row.t5 || '',
 +
        row.t20 || '',
 +
        row.t100 || '',
 +
        row.t500 || '',
 +
       ].join(','),
 +
    )
 +
    .join('\n')
   −
function NestedMap () {
+
function NestedMap() {
 
   return {
 
   return {
 
     index: [],
 
     index: [],
 
     arr: [],
 
     arr: [],
 
     map: {},
 
     map: {},
     insert: function (keys, value) {
+
     insert: function(keys, value) {
 
       let index = this.index
 
       let index = this.index
 
       let arr = this.arr
 
       let arr = this.arr
Line 11,136: Line 11,162:  
       }
 
       }
 
       arr.push(value)
 
       arr.push(value)
     }
+
     },
 
   }
 
   }
 
}
 
}
Line 11,148: Line 11,174:  
   return tables
 
   return tables
 
}
 
}
 +
 +
const serverNames = [
 +
  'Yokosuka (横須賀鎮守府)',
 +
  'Kure (呉鎮守府)',
 +
  'Sasebo (佐世保鎮守府)',
 +
  'Maizuru (舞鶴鎮守府)',
 +
  'Ominato (大湊警備府)',
 +
  'Truk (トラック泊地)',
 +
  'Lingga (リンガ泊地)',
 +
  'Rabaul (ラバウル基地)',
 +
  'Shortland (ショートランド泊地)',
 +
  'Buin (ブイン基地)',
 +
  'Tawi-Tawi (タウイタウイ泊地)',
 +
  'Palau (パラオ泊地)',
 +
  'Brunei (ブルネイ泊地)',
 +
  'Hitokappu (単冠湾泊地)',
 +
  'Paramushir (幌筵泊地)',
 +
  'Sukumo (宿毛湾泊地)',
 +
  'Kanoya (鹿屋基地)',
 +
  'Iwagawa (岩川基地)',
 +
  'Saiki (佐伯湾泊地)',
 +
  'Hashirajima (柱島泊地)',
 +
]
    
// Generate colored tables in wikitext.
 
// Generate colored tables in wikitext.
const genWikitext = tables => {
+
const genWikitext = (tables, summary) => {
 
   const color = servers => {
 
   const color = servers => {
 +
    if (servers.colored) {
 +
      return
 +
    }
 +
    servers.colored = true
 
     const sortedTiers = {
 
     const sortedTiers = {
       't1': servers.map(s => s.t1).sort((a, b) => a - b).filter(x => x > 0),
+
       t1: servers
       't5': servers.map(s => s.t5).sort((a, b) => a - b).filter(x => x > 0),
+
        .map(s => s.t1)
       't20': servers.map(s => s.t20).sort((a, b) => a - b).filter(x => x > 0),
+
        .sort((a, b) => a - b)
       't100': servers.map(s => s.t100).sort((a, b) => a - b).filter(x => x > 0),
+
        .filter(x => x > 0),
       't500': servers.map(s => s.t500).sort((a, b) => a - b).filter(x => x > 0)
+
       t5: servers
 +
        .map(s => s.t5)
 +
        .sort((a, b) => a - b)
 +
        .filter(x => x > 0),
 +
       t20: servers
 +
        .map(s => s.t20)
 +
        .sort((a, b) => a - b)
 +
        .filter(x => x > 0),
 +
       t100: servers
 +
        .map(s => s.t100)
 +
        .sort((a, b) => a - b)
 +
        .filter(x => x > 0),
 +
       t500: servers
 +
        .map(s => s.t500)
 +
        .sort((a, b) => a - b)
 +
        .filter(x => x > 0),
 
     }
 
     }
 
     const formatCells = (server, tier) => {
 
     const formatCells = (server, tier) => {
Line 11,167: Line 11,235:  
         '1': value => `style="background:#FFF9C4"|${value}`,
 
         '1': value => `style="background:#FFF9C4"|${value}`,
 
         '2': value => `style="background:#FFCC80"|${value}`,
 
         '2': value => `style="background:#FFCC80"|${value}`,
         '3': value => `style="background:#FFCDD2"|'''${value}'''`
+
         '3': value => `style="background:#FFCDD2"|'''${value}'''`,
 
       }
 
       }
 
       const sorted = sortedTiers[tier]
 
       const sorted = sortedTiers[tier]
 
       const value = server[tier] || ''
 
       const value = server[tier] || ''
 
       const i1 = sorted.indexOf(value)
 
       const i1 = sorted.indexOf(value)
       const i2 = sorted.slice().reverse().indexOf(value)
+
       const i2 = sorted
 +
        .slice()
 +
        .reverse()
 +
        .indexOf(value)
 
       if (sorted.length < 6) {
 
       if (sorted.length < 6) {
 
         server[tier] = formatters[0](value)
 
         server[tier] = formatters[0](value)
Line 11,202: Line 11,273:  
   }
 
   }
   −
   const monthNames = [
+
   const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
  −
  ]
      
   let wikitext = ''
 
   let wikitext = ''
 
   for (const year of tables.index) {
 
   for (const year of tables.index) {
 
     wikitext += `==${year}==\n`
 
     wikitext += `==${year}==\n`
     for (const month of tables.map[year].index) {
+
     if (summary) {
      wikitext += `===${monthNames[month - 1]}===\n`
+
      for (const top of [1, 5, 20, 100, 500]) {
      for (const time of tables.map[year].map[month].index) {
+
        const months = [...tables.map[year].index].reverse()
        wikitext += `{| {{RankingTable|${year}|${month}|${time.split(' ')[0]}|${time.split(' ')[1]}}}\n`
+
        wikitext += `{| {{FancyTable|sortable|text_align=center|width=unset}}\n|+style="white-space:nowrap"|Top ${top}${
        const servers = tables.map[year].map[month].map[time].arr
+
          top === 5 && year === 2014 ? ` (3 before July)` : ''
        color(servers)
+
        }\n!Server!!${months.map(i => monthNames[i - 1]).join('!!')}\n`
        let first = true
+
        for (let n = 0; n < 20; ++n) {
        for (const server of servers) {
+
          let notEmpty = false
          wikitext += genRowWikitext(first, server) + '\n'
+
          let s = `|-\n|lang="ja"|${serverNames[n].split(' ')[0]}\n`
           first = false
+
          for (const month of months) {
 +
            const time = tables.map[year].map[month].index[1] || tables.map[year].map[month].index[0]
 +
            color(tables.map[year].map[month].map[time].arr)
 +
            const server = tables.map[year].map[month].map[time].arr[n]
 +
            s += `|${(server && server[`t${top}`]) || ''}\n`
 +
            if (server && server[`t${top}`]) {
 +
              notEmpty = true
 +
            }
 +
          }
 +
          if (notEmpty) {
 +
            wikitext += s
 +
           }
 
         }
 
         }
 
         wikitext += '|}\n'
 
         wikitext += '|}\n'
 +
      }
 +
    } else {
 +
      for (const month of tables.map[year].index) {
 +
        wikitext += `===${monthNames[month - 1]}===\n`
 +
        for (const time of tables.map[year].map[month].index) {
 +
          wikitext += `{| {{RankingTable|${year}|${month}|${time.split(' ')[0]}|${time.split(' ')[1]}}}\n`
 +
          const servers = tables.map[year].map[month].map[time].arr
 +
          color(servers)
 +
          let first = true
 +
          for (const server of servers) {
 +
            wikitext += genRowWikitext(first, server) + '\n'
 +
            first = false
 +
          }
 +
          wikitext += '|}\n'
 +
        }
 
       }
 
       }
 
     }
 
     }
Line 11,226: Line 11,321:  
   return wikitext
 
   return wikitext
 
}
 
}
 +
 +
// Parse the page, generate and copy CSV.
 +
copy(genCSV(parseRows()))
    
// Parse the page, regenerate and copy colored tables in wikitext.
 
// Parse the page, regenerate and copy colored tables in wikitext.
 
copy(genWikitext(groupRows(parseRows())))
 
copy(genWikitext(groupRows(parseRows())))
   −
// Parse the page, generate and copy CSV.
+
// Parse the page, regenerate and copy colored summary tables in wikitext.
copy(genCSV(parseRows()))
+
copy(genWikitext(groupRows(parseRows()), true))
 
  −
const serverNames = [
  −
  'Yokosuka (横須賀鎮守府)',
  −
  'Kure (呉鎮守府)',
  −
  'Sasebo (佐世保鎮守府)',
  −
  'Maizuru (舞鶴鎮守府)',
  −
  'Ominato (大湊警備府)',
  −
  'Truk (トラック泊地)',
  −
  'Lingga (リンガ泊地)',
  −
  'Rabaul (ラバウル基地)',
  −
  'Shortland (ショートランド泊地)',
  −
  'Buin (ブイン基地)',
  −
  'Tawi-Tawi (タウイタウイ泊地)',
  −
  'Palau (パラオ泊地)',
  −
  'Brunei (ブルネイ泊地)',
  −
  'Hitokappu (単冠湾泊地)',
  −
  'Paramushir (幌筵泊地)',
  −
  'Sukumo (宿毛湾泊地)',
  −
  'Kanoya (鹿屋基地)',
  −
  'Iwagawa (岩川基地)',
  −
  'Saiki (佐伯湾泊地)',
  −
  'Hashirajima (柱島泊地)'
  −
]
      
// Generate a new table body from a DSV string. Supports any non-number delimiter.
 
// Generate a new table body from a DSV string. Supports any non-number delimiter.
 
const genTableFromDsv = s =>
 
const genTableFromDsv = s =>
   s.trim().split(/\r?\n/).filter((l) => l).map((line, i) => {
+
   s
    const p4 = line.match(/(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/)
+
    .trim()
    const p5 = line.match(/(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/)
+
    .split(/\r?\n/)
    const ns = p5 ? p5.slice(1) : p4 ? [''].concat(p4.slice(1)) : ['', '', '', '', '']
+
    .filter(l => l)
    return `|-
+
    .map((line, i) => {
 +
      const p4 = line.match(/(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/)
 +
      const p5 = line.match(/(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/)
 +
      const ns = p5 ? p5.slice(1) : p4 ? [''].concat(p4.slice(1)) : ['', '', '', '', '']
 +
      return `|-
 
|${i + 1}
 
|${i + 1}
 
|lang="ja"|${serverNames[i]}
 
|lang="ja"|${serverNames[i]}
Line 11,270: Line 11,349:  
|${ns[3] > 0 ? ns[3] : ''}
 
|${ns[3] > 0 ? ns[3] : ''}
 
|${ns[4] > 0 ? ns[4] : ''}`
 
|${ns[4] > 0 ? ns[4] : ''}`
  }).join('\n')
+
    })
 +
    .join('\n')
 
</pre>
 
</pre>
 
{{SectionEnd}}
 
{{SectionEnd}}
cssedit, gkautomate
6,941

edits

Navigation menu