Skip to content

Instantly share code, notes, and snippets.

@ncla
Created November 16, 2014 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncla/cb09d8b9dacc3738c116 to your computer and use it in GitHub Desktop.
Save ncla/cb09d8b9dacc3738c116 to your computer and use it in GitHub Desktop.
Dirty script to generate match thread for r/csgobetting based on HLTV match page
// ==UserScript==
// @name Match thread creator from HLTV match pages
// @namespace http://ncla.me
// @version 0.1
// @description Generated markdown for match threads
// @author ncla
// @match http://www.hltv.org/match/*
// @require http://code.jquery.com/jquery-1.11.1.min.js
// @grant none
// ==/UserScript==
var matchTemplate = (function () {/*
**Links**: [HLTV](url) | [CSGL](url)
-------------------------
*Match Information*
**Date**: 25th of February [Example]
**Time**: 19:00 CET [Example]
**Tournament/League**: [TOURNAMENT NAME]
**LAN/Online**: LAN [Example]
**Maps**: BO1 [Example]
---------------
**Team1**: Player1, Player2, Player3, Player4, Player5
--------------------------------------
**Team2**: Player1, Player2, Player3, Player4, Player5
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
var threadTitle = "XXX vs. XXX | BO1 or BO3 | DD.MM.YY | Time (In CEST/CET)";
//console.log(matchTemplate);
$(document).ready(function() {
var matchContainer = $(".centerNoHeadline:eq(0)");
//console.log(matchContainer);
var maps = $(".headertext:contains('Maps')", matchContainer).parent().parent();
var matchFormat = $("#mapformatbox", maps).text();
var matchFormatTextLines = matchFormat.split("\n");
var bestOfFormat = false;
$.each(matchFormatTextLines, function(i, v) {
if(v.indexOf("Best of") != -1) {
bestOfFormat = v.trim();
}
});
//console.log(bestOfFormat);
// match head
var matchHead = $("div[style='text-align: center;']:eq(0)", matchContainer);
var teamA_name = $("span[style='font-size: 26px']:eq(0)", matchHead).text().trim();
var teamB_name = $("span[style='font-size: 26px']:eq(1)", matchHead).text().trim();
//console.log(teamA_name); console.log(teamB_name);
// date and time block
var timeAndDate = $("div[style='text-align:center;font-size: 18px;']:eq(0)", matchContainer);
var date = $(timeAndDate).contents().eq(0).text().trim();
var time = $(timeAndDate).contents().eq(1).text().trim() + " CET";
//console.log(date); console.log(time);
var lineUpBlock = $("div.hotmatchbox[style='text-align: center;']", matchContainer);
var teamA_lineup = $(lineUpBlock).eq(0).text().trim().replace(" ", "").replace(/\s{2,}/g, ' ');
var teamB_lineup = $(lineUpBlock).eq(1).text().trim().replace(" ", "").replace(/\s{2,}/g, ' ');
//console.log(teamA_lineup); console.log(teamB_lineup);
var tournamentName = $("a[href*='&eventid=']:eq(0)", matchContainer).text().trim();
//console.log(tournamentName);
matchTemplate = matchTemplate.replace("[HLTV](url)", "[HLTV]("+window.location+")").replace("[CSGL](url)", "[CSGL](http://csgolounge.com/match?m=1337)")
.replace("25th of February [Example]", date).replace("19:00 CET [Example]", time)
.replace("[TOURNAMENT NAME]", tournamentName).replace("LAN [Example]", "Online").replace("BO1 [Example]", bestOfFormat)
.replace("**Team1**: Player1, Player2, Player3, Player4, Player5", "**"+teamA_name+"**: " + teamA_lineup)
.replace("**Team2**: Player1, Player2, Player3, Player4, Player5", "**"+teamB_name+"**: " + teamB_lineup);
var shortBestOfType = "BO1";
if(bestOfFormat.indexOf("3") != -1) {
shortBestOfType = "BO3";
}
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = dd+'.'+mm+'.'+yyyy;
threadTitle = threadTitle.replace("XXX vs. XXX", teamA_name+" vs. "+teamB_name).replace("BO1 or BO3", shortBestOfType).replace("DD.MM.YY", today).replace("Time (In CEST/CET)", time);
console.log(threadTitle);
console.log(matchTemplate);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment