MCPcopy
hub / github.com/Justineo/github-hovercard / extractElem

Function extractElem

src/hovercard.js:2136–2491  ·  view source on GitHub ↗
(context, el, strategy)

Source from the content-addressed store, hash-verified

2134 }
2135
2136 function extractElem (context, el, strategy) {
2137 if (context && !context.contains(el)) {
2138 return
2139 }
2140 let elem = $(el)
2141 if (getExtracted(elem) || elem.is(BLACK_LIST_SELECTOR)) {
2142 // skip processed elements
2143 return
2144 }
2145 let target
2146 let username // {{user}}
2147 let repo // {{repo}}
2148 let fullRepo // {{user}}/{{repo}}
2149 let issue // {{issue}}
2150 let fullIssue // {{user}}/{{repo}}#{{issue}}
2151 let comment // {{comment}}
2152 let fullComment // {{user}}/{{repo}}:{{issue}}
2153 let commit // {{commit}}
2154 let fullCommit // {{user}}/{{repo}}@{{commit}}
2155 switch (strategy) {
2156 case EXTRACTOR.TEXT_USER: {
2157 username = trim(elem.text().replace(/[@/]/g, ''))
2158 target = $(`<span>${elem.text()}</span>`)
2159 elem.empty().append(target)
2160 break
2161 }
2162 case EXTRACTOR.TITLE_USER: {
2163 username = trim((elem.attr('title') || '').replace(/[@/]/g, ''))
2164 break
2165 }
2166 case EXTRACTOR.ALT_USER: {
2167 username = trim(
2168 (elem.attr('alt') || '').split(/\s+/)[0].replace(/[@/]/g, '')
2169 )
2170 break
2171 }
2172 case EXTRACTOR.HREF_USER: {
2173 username = trim((elem.attr('href') || '').replace(/[@/]/g, ''))
2174 break
2175 }
2176 case EXTRACTOR.TEXT_MY_REPO: {
2177 let repo = trim(elem.text())
2178 if (me && repo.indexOf('/') === -1) {
2179 fullRepo = `${me}/${repo}`
2180 break
2181 }
2182 }
2183 case EXTRACTOR.SLUG: {
2184 let slug = elem.text()
2185 let match = slug.match(SLUG_PATTERN)
2186 username = trim(match && match[1])
2187 repo = trim(match && match[2])
2188 issue = trim(match && match[3])
2189 commit = trim(match && match[4])
2190 if (username && repo) {
2191 fullRepo = username + '/' + repo
2192
2193 // special case for code search highlight

Callers 1

extractFunction · 0.70

Calls 8

containsMethod · 0.80
getExtractedFunction · 0.70
trimFunction · 0.70
encodeHTMLFunction · 0.70
markExtractedFunction · 0.70
getNextTextNodeFunction · 0.70
fixRepoSlugFunction · 0.70

Tested by

no test coverage detected