{"size": 1687, "ext": "js", "max_stars_repo_path": "src/detectors/bold_element_font_weight.js", "max_stars_repo_name": "sh-web/compatibility-detector", "max_stars_repo_stars_event_min_datetime": "2018-07-02T06:04:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-04T01:47:20.000Z", "max_issues_repo_path": "src/detectors/bold_element_font_weight.js", "max_issues_repo_name": "sh-web/compatibility-detector", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/detectors/bold_element_font_weight.js", "max_forks_repo_name": "sh-web/compatibility-detector", "max_forks_repo_forks_event_min_datetime": "2018-01-29T13:12:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-25T06:45:14.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 5, "avg_line_length": 29.5964912281, "max_line_length": 75, "alphanum_fraction": 0.6698280972}
/**
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

addScriptToInject(function() {

chrome_comp.CompDetect.declareDetector(

'bold_element_font_weight',

chrome_comp.CompDetect.ScanDomBaseDetector,

null, // constructor

function checkNode(node, context) {
  if (Node.ELEMENT_NODE != node.nodeType ||
      Node.ELEMENT_NODE != node.parentNode.nodeType)
    return;

  var fontWeight = chrome_comp.getDefinedStylePropertyByName(node, true,
      'font-weight');
  var parentFontWeight = parseInt(
      chrome_comp.getComputedStyle(node.parentNode).fontWeight, 10);

  if ((fontWeight == 'bolder' && parentFontWeight <= 300) ||
      (fontWeight == 'lighter' && parentFontWeight >= 800)) {
    this.addProblem('RA3002', [node]);
    return;
  }

  if (!fontWeight) {
    var tagName = node.tagName;
    if (tagName == 'STRONG' || tagName == 'B' || tagName == 'TH' ||
        // Check H1 ~ H6
        (tagName.length == 2 && tagName[0] == 'H' &&
        tagName[1] >= '1' && tagName[1] <= '6')) {
      if (!isNaN(parentFontWeight) && parentFontWeight <= 300)
        this.addProblem('RA3002', [node]);
    }
  }
}
); // declareDetector

});
