Skip to content

Instantly share code, notes, and snippets.

@SammyVimes
Created April 9, 2018 08:57
Show Gist options
  • Save SammyVimes/c68e7b945df9ba10d15968297743c3fd to your computer and use it in GitHub Desktop.
Save SammyVimes/c68e7b945df9ba10d15968297743c3fd to your computer and use it in GitHub Desktop.
Literature sources generator
var $ = jQuery;
function getProp(propName) {
var props = "";
$(".eItemProperties_name").each(function(i, e){
if ($(e).text().indexOf(propName) != -1) {
props = $($(e).siblings()[0]).text().replace(/\s+/g, " ").trim();
}
});
return props;
}
function getAuthors() {
return getProp("Автор");
}
function getTitle() {
return $(".bItemName").text().trim();
}
function getPages() {
return getProp("Количество страниц");
}
function getPublisher() {
return getProp("Издательство");
}
function getYear() {
return getProp("Год выпуска");
}
function getCity() {
var publisher = getPublisher();
var map = {
"Питер": "СПб"
};
if (Object.keys(map).indexOf(publisher) != -1) {
return map[publisher];
}
var cities = ["СПб", "М"];
var max = cities.length - 1;
var min = 0;
return cities[Math.round(min + (Math.random() * (max - min)))];
}
function Author(name) {
var s = name.split(" ");
var fir = s[0];
var sur = s[1];
this.getComma = function() {
return sur + ", " + fir.charAt(0) + ".";
};
this.getNormal = function() {
return fir.charAt(0) + ". " + sur;
};
}
function generateBook() {
$(".eItemProperties_all.jsShowAll.mRoll").click();
var authors = getAuthors().split(", ");
var first = new Author(authors[0]);
var arr = [];
for (var i = 0; i < authors.length; i++) {
arr[i] = new Author(authors[i]).getNormal();
}
return first.getComma() + " " + getTitle() + " / " + arr.join(", ") + ". — " + getCity() + ": " + getPublisher() + ", " + getYear() + ". — " + getPages() + " с.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment