Skip to content

Instantly share code, notes, and snippets.

@wein3967
Last active April 6, 2017 13:18
Show Gist options
  • Select an option

  • Save wein3967/3bc605460091cabd71b31a005d3c012a to your computer and use it in GitHub Desktop.

Select an option

Save wein3967/3bc605460091cabd71b31a005d3c012a to your computer and use it in GitHub Desktop.
This is a DIM specific script that is run from the Chrome developer tools console in an active DIM tab
// This is a DIM specific script that can be run in the Developer Console in Chrome on a DIM tab.
// it writes out a csv string with name and perks for weapons.
// FUNCTIONS
function isWeapon(myItem) {
return myItem.type === "Primary" ||
myItem.type === "Special" ||
myItem.type === "Heavy" &&
myItem.name.indexOf("Engram") == -1; // Filtering out various Engrams
};
function isRealPerk(myItem) { // Omitting "perks" I don't really care about
return myItem !== "Infuse" &&
myItem !== "Ascend" &&
myItem !== "Kinetic Damage" &&
myItem !== "Solar Damage" &&
myItem !== "Arc Damage" &&
myItem !== "Void Damage" &&
myItem !== "Upgrade Damage" &&
myItem !== "Red Chroma" &&
myItem !== "Blue Chroma" &&
myItem !== "Yellow Chroma" &&
myItem !== "White Chroma" &&
myItem !== "Deactivate Chroma";
};
function getItemString(item) {
var descriptionString = item.id + ',' +
',' + // Placeholder for my Keep/Trash column
item.locked + ',' +
item.classTypeName + ',' +
item.tier + ',' +
item.year + ',' +
item.sort + ',' +
item.type + ',' +
item.weaponClassName + ',' +
item.name;
//item.dmg + ',';
switch (item.name) {
case "Murmur":
descriptionString = descriptionString + ',' + "solar/arc"
break;
default :
if (item.dmg === null) { // Handles some Exotic primaries
descriptionString = descriptionString + ',' + "kinetic"
} else {
descriptionString = descriptionString + ',' + item.dmg
};
};
if (item.primStat == undefined) { // Handles the few pieces of armor that have no light value (e.g. SRL Legs)
descriptionString = descriptionString + ',' + '0';
} else {
descriptionString = descriptionString + ',' + item.primStat.value;
};
return descriptionString;
};
function getPerkList(testObject) {
if (!!testObject.talentGrid) { // Handles the items of armor that have no perks (e.g. Year 1 class items)
var perkList = [];
var color = "None";
for (j = 0; j < testObject.talentGrid.nodes.length; j++) {
if (testObject.talentGrid.nodes[j].hidden == false) { // Ignore hidden perks
perkList.push(testObject.talentGrid.nodes[j].name);
};
};
color = getColor(perkList);
perkList = perkList.filter(isRealPerk);
perkList.unshift(color); // Add color to the front of the perkList
return perkList;
} else {
return "None,None";
};
};
function getColor(perks) {
var chromaColor = "None";
for (k = 0; k < perks.length; k++) {
switch (perks[k]) {
case "Red Chroma":
chromaColor = "Red";
break;
case "Blue Chroma":
chromaColor = "Blue";
break;
case "Yellow Chroma":
chromaColor = "Yellow";
break;
case "White Chroma":
chromaColor = "White";
break;
};
};
return chromaColor;
};
/////////////////////////////////////////////////////////////////////
// MAIN CODE
var stuff = angular.element(document.body).injector().get('dimStoreService').getStores();
var guardian1_Items = (stuff.length >= 2) ? stuff[0].items : [];
var guardian2_Items = (stuff.length >= 3) ? stuff[1].items : [];
var guardian3_Items = (stuff.length >= 4) ? stuff[2].items : [];
var vaultItems = stuff[stuff.length - 1].items;
var allItems = guardian1_Items.concat(guardian2_Items, guardian3_Items, vaultItems);
var allFilteredItems = allItems.filter(isWeapon); // Filter for only weapons
var descString = "IndexID,Status,IsLocked,Class,Tier,Year,Weapon,Type,Subclass,Name,DamageType,Light,Color,Perks" + '\n';
for (i = 0; i < allFilteredItems.length; i++) {
descString = descString +
getItemString(allFilteredItems[i]) + ',' +
getPerkList(allFilteredItems[i]) +
'\n';
};
descString;
Copy link

ghost commented Jul 19, 2016

I'm entering this is DIM and I'm getting an error.

VM228:185 Uncaught TypeError: Cannot read property 'vm' of undefined(…)(anonymous function) @ VM228:185

Any help would be appreciated. This is a great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment